public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH -tip 01/14] perf probe: Cleanup struct session in  builtin-probe.c
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
  2009-12-15 15:26 ` [PATCH -tip 02/14] perf probe: Check the result of e_snprintf() Masami Hiramatsu
@ 2009-12-15 15:26 ` Masami Hiramatsu
  2009-12-15 19:27   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:27 ` [PATCH -tip 09/14] perf probe: Add glob matching support on --del Masami Hiramatsu
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:26 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Cleanup struct session in builtin-probe.c, including
change need_dwarf to bool and move listing flag into
struct session as list_events flag.
This also changes parse_perf_probe_event() interface
due to code readability.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/builtin-probe.c    |   13 +++++++------
 tools/perf/util/probe-event.c |   12 +++++++-----
 tools/perf/util/probe-event.h |    4 +++-
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 5a47c1e..559eeb4 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -59,13 +59,13 @@ const char *default_search_path[NR_SEARCH_PATH] = {
 static struct {
 	char *vmlinux;
 	char *release;
-	int need_dwarf;
+	bool need_dwarf;
+	bool list_events;
 	int nr_probe;
 	struct probe_point probes[MAX_PROBES];
 	struct strlist *dellist;
 } session;
 
-static bool listing;
 
 /* Parse an event definition. Note that any error must die. */
 static void parse_probe_event(const char *str)
@@ -77,7 +77,7 @@ static void parse_probe_event(const char *str)
 		die("Too many probes (> %d) are specified.", MAX_PROBES);
 
 	/* Parse perf-probe event into probe_point */
-	session.need_dwarf = parse_perf_probe_event(str, pp);
+	parse_perf_probe_event(str, pp, &session.need_dwarf);
 
 	pr_debug("%d arguments\n", pp->nr_args);
 }
@@ -166,7 +166,8 @@ static const struct option options[] = {
 	OPT_STRING('k', "vmlinux", &session.vmlinux, "file",
 		"vmlinux/module pathname"),
 #endif
-	OPT_BOOLEAN('l', "list", &listing, "list up current probe events"),
+	OPT_BOOLEAN('l', "list", &session.list_events,
+		    "list up current probe events"),
 	OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.",
 		opt_del_probe_event),
 	OPT_CALLBACK('a', "add", NULL,
@@ -207,10 +208,10 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 	if (argc > 0)
 		parse_probe_event_argv(argc, argv);
 
-	if ((session.nr_probe == 0 && !session.dellist && !listing))
+	if ((!session.nr_probe && !session.dellist && !session.list_events))
 		usage_with_options(probe_usage, options);
 
-	if (listing) {
+	if (session.list_events) {
 		if (session.nr_probe != 0 || session.dellist) {
 			pr_warning("  Error: Don't use --list with"
 				   " --add/--del.\n");
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d14a458..add379c 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -150,10 +150,13 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
 }
 
 /* Parse perf-probe event definition */
-int parse_perf_probe_event(const char *str, struct probe_point *pp)
+void parse_perf_probe_event(const char *str, struct probe_point *pp,
+			    bool *need_dwarf)
 {
 	char **argv;
-	int argc, i, need_dwarf = 0;
+	int argc, i;
+
+	*need_dwarf = false;
 
 	argv = argv_split(str, &argc);
 	if (!argv)
@@ -164,7 +167,7 @@ int parse_perf_probe_event(const char *str, struct probe_point *pp)
 	/* Parse probe point */
 	parse_perf_probe_probepoint(argv[0], pp);
 	if (pp->file || pp->line)
-		need_dwarf = 1;
+		*need_dwarf = true;
 
 	/* Copy arguments and ensure return probe has no C argument */
 	pp->nr_args = argc - 1;
@@ -177,12 +180,11 @@ int parse_perf_probe_event(const char *str, struct probe_point *pp)
 			if (pp->retprobe)
 				semantic_error("You can't specify local"
 						" variable for kretprobe");
-			need_dwarf = 1;
+			*need_dwarf = true;
 		}
 	}
 
 	argv_free(argv);
-	return need_dwarf;
 }
 
 /* Parse kprobe_events event into struct probe_point */
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index f752159..028575b 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -1,10 +1,12 @@
 #ifndef _PROBE_EVENT_H
 #define _PROBE_EVENT_H
 
+#include <stdbool.h>
 #include "probe-finder.h"
 #include "strlist.h"
 
-extern int parse_perf_probe_event(const char *str, struct probe_point *pp);
+extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
+				   bool *need_dwarf);
 extern int synthesize_perf_probe_event(struct probe_point *pp);
 extern void parse_trace_kprobe_event(const char *str, char **group,
 				     char **event, struct probe_point *pp);


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 00/14] perf-probe updates
@ 2009-12-15 15:26 Masami Hiramatsu
  2009-12-15 15:26 ` [PATCH -tip 02/14] perf probe: Check the result of e_snprintf() Masami Hiramatsu
                   ` (14 more replies)
  0 siblings, 15 replies; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:26 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Hi Ingo,

Here are several bugfixes and updates of perf-probe.
This updates includes below features.

  - Support checking kernel Build-ID
	Comparing vmlinux build-id and running kernel build-id
	can prevent user to set incorrect probes by using
	old/incorrect vmlinux.

  - Symbol search by libelf/kallsyms
	This allows to check probed symbol exists in the kernel
	even if debuginfo is not available.

  - Support glob expression with --del option (like --del '*')
	This allows users to use wildcard for specifying
	deleting events.

  - Reject adding same-name events
	Rejecting to add event which name already exists.

  - Support event name specifying for new events
	This allows users to set their own name to new
	events. Currently setting group name is not
	allowed, because it will conflict with other
	tracepoints and kmem event.

I think the glob expression (wildcard matching) can be
applied to other perf tools for choosing events, and it
will give user better experience :-)


Here are updated todo list.

Long-term TODOs (future features):
  - Support --line option to show which lines user can probe
  - Support lazy string matching(glob?) for selecting probing
    line
  - Support sys_perf_counter_open (for non-root users)
  - Support tracing static variables (non global)
  - Support variable types from debuginfo (e.g. char, int, ...)
  - Support fields of data structures (var->field)
  - Support array (var[N])
  - Support dynamic array-indexing (var[var2])
  - Support string/dynamic arrays (*var, var[N..M])
  - Support force type-casting ((type)var)
  - Support the type of return value

Miscs:
  - Better support for probes on modules
  - Move onto libdw/libdwfl
  - Storing file name/line number information in the
    kernel for listing events
  

Thank you,

---

Masami Hiramatsu (14):
      perf probe: Fix to show which probe point is not found
      perf probe: Check symbols in symtab/kallsyms
      perf probe: Check build-id of vmlinux
      perf probe: Reject second attempt of adding same-name event
      perf probe: Support event name for --add option
      perf probe: Add glob matching support on --del
      perf probe: Use strlist__for_each macros in probe-event.c
      perf tools: Add for_each macros for strlist
      perf probe: Fix --del to update current event list
      perf probe: Fix --del to show info instead of warning
      perf probe: Show need-dwarf message only if it is really needed
      perf probe: Check hyphen only argument
      perf probe: Check the result of e_snprintf()
      perf probe: Cleanup struct session in builtin-probe.c


 tools/perf/Documentation/perf-probe.txt |    3 
 tools/perf/builtin-probe.c              |  145 ++++++++++++----------
 tools/perf/util/event.h                 |    2 
 tools/perf/util/map.c                   |   14 +-
 tools/perf/util/probe-event.c           |  208 +++++++++++++++++++++----------
 tools/perf/util/probe-event.h           |   11 +-
 tools/perf/util/probe-finder.c          |    4 -
 tools/perf/util/probe-finder.h          |    3 
 tools/perf/util/string.c                |   25 ++++
 tools/perf/util/string.h                |    2 
 tools/perf/util/strlist.c               |    6 -
 tools/perf/util/strlist.h               |   41 ++++++
 12 files changed, 318 insertions(+), 146 deletions(-)

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com

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

* [PATCH -tip 02/14] perf probe: Check the result of e_snprintf()
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
@ 2009-12-15 15:26 ` Masami Hiramatsu
  2009-12-15 19:26   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:26 ` [PATCH -tip 01/14] perf probe: Cleanup struct session in builtin-probe.c Masami Hiramatsu
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:26 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Fix show_perf_probe_event() to check the result of e_snprintf().

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/util/probe-event.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index add379c..1653a62 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -385,10 +385,12 @@ static void clear_probe_point(struct probe_point *pp)
 static void show_perf_probe_event(const char *group, const char *event,
 				  const char *place, struct probe_point *pp)
 {
-	int i;
+	int i, ret;
 	char buf[128];
 
-	e_snprintf(buf, 128, "%s:%s", group, event);
+	ret = e_snprintf(buf, 128, "%s:%s", group, event);
+	if (ret < 0)
+		die("Failed to copy event: %s", strerror(-ret));
 	printf("  %-40s (on %s", buf, place);
 
 	if (pp->nr_args > 0) {


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 03/14] perf probe: Check hyphen only argument
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (6 preceding siblings ...)
  2009-12-15 15:27 ` [PATCH -tip 06/14] perf probe: Fix --del to update current event list Masami Hiramatsu
@ 2009-12-15 15:27 ` Masami Hiramatsu
  2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:27 ` [PATCH -tip 08/14] perf probe: Use strlist__for_each macros in probe-event.c Masami Hiramatsu
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:27 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Check hyphen only command argument, because perf-probe doesn't
support event recording feature yet.

e.g.

 # perf probe -
  Error: '-' is not supported.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/builtin-probe.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 559eeb4..919037b 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -205,8 +205,13 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 
 	argc = parse_options(argc, argv, options, probe_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
-	if (argc > 0)
+	if (argc > 0) {
+		if (strcmp(argv[0], "-") == 0) {
+			pr_warning("  Error: '-' is not supported.\n");
+			usage_with_options(probe_usage, options);
+		}
 		parse_probe_event_argv(argc, argv);
+	}
 
 	if ((!session.nr_probe && !session.dellist && !session.list_events))
 		usage_with_options(probe_usage, options);


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 08/14] perf probe: Use strlist__for_each macros in  probe-event.c
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (7 preceding siblings ...)
  2009-12-15 15:27 ` [PATCH -tip 03/14] perf probe: Check hyphen only argument Masami Hiramatsu
@ 2009-12-15 15:27 ` Masami Hiramatsu
  2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:28 ` [PATCH -tip 10/14] perf probe: Support event name for --add option Masami Hiramatsu
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:27 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Use strlist__for_each macros instead of using strlist__entry()
and index variable.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/util/probe-event.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 4055d01..fa7e8e5 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -404,7 +404,6 @@ static void show_perf_probe_event(const char *group, const char *event,
 /* List up current perf-probe events */
 void show_perf_probe_events(void)
 {
-	unsigned int i;
 	int fd, nr;
 	char *group, *event;
 	struct probe_point pp;
@@ -415,8 +414,7 @@ void show_perf_probe_events(void)
 	rawlist = get_trace_kprobe_event_rawlist(fd);
 	close(fd);
 
-	for (i = 0; i < strlist__nr_entries(rawlist); i++) {
-		ent = strlist__entry(rawlist, i);
+	strlist__for_each(ent, rawlist) {
 		parse_trace_kprobe_event(ent->s, &group, &event, &pp);
 		/* Synthesize only event probe point */
 		nr = pp.nr_args;
@@ -436,7 +434,6 @@ void show_perf_probe_events(void)
 /* Get current perf-probe event names */
 static struct strlist *get_perf_event_names(int fd, bool include_group)
 {
-	unsigned int i;
 	char *group, *event;
 	char buf[128];
 	struct strlist *sl, *rawlist;
@@ -445,8 +442,7 @@ static struct strlist *get_perf_event_names(int fd, bool include_group)
 	rawlist = get_trace_kprobe_event_rawlist(fd);
 
 	sl = strlist__new(true, NULL);
-	for (i = 0; i < strlist__nr_entries(rawlist); i++) {
-		ent = strlist__entry(rawlist, i);
+	strlist__for_each(ent, rawlist) {
 		parse_trace_kprobe_event(ent->s, &group, &event, NULL);
 		if (include_group) {
 			if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
@@ -562,7 +558,6 @@ static void del_trace_kprobe_event(int fd, const char *group,
 void del_trace_kprobe_events(struct strlist *dellist)
 {
 	int fd;
-	unsigned int i;
 	const char *group, *event;
 	char *p, *str;
 	struct str_node *ent;
@@ -572,8 +567,7 @@ void del_trace_kprobe_events(struct strlist *dellist)
 	/* Get current event names */
 	namelist = get_perf_event_names(fd, true);
 
-	for (i = 0; i < strlist__nr_entries(dellist); i++) {
-		ent = strlist__entry(dellist, i);
+	strlist__for_each(ent, dellist) {
 		str = strdup(ent->s);
 		if (!str)
 			die("Failed to copy event.");


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 09/14] perf probe: Add glob matching support on --del
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
  2009-12-15 15:26 ` [PATCH -tip 02/14] perf probe: Check the result of e_snprintf() Masami Hiramatsu
  2009-12-15 15:26 ` [PATCH -tip 01/14] perf probe: Cleanup struct session in builtin-probe.c Masami Hiramatsu
@ 2009-12-15 15:27 ` Masami Hiramatsu
  2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:27 ` [PATCH -tip 05/14] perf probe: Fix --del to show info instead of warning Masami Hiramatsu
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:27 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Add glob-expression matching support on --del option.
You can use wildcards for specifying deleting events.
e.g.

 Clear all probe events:

 # perf probe --del '*'

 Clear probes on schedule():

 # perf probe --del 'schedule*'

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/util/probe-event.c |   52 +++++++++++++++++++++++++++++++----------
 tools/perf/util/string.c      |   25 ++++++++++++++++++++
 tools/perf/util/string.h      |    2 ++
 3 files changed, 66 insertions(+), 13 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index fa7e8e5..af7cc76 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -532,27 +532,51 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 	close(fd);
 }
 
+static void __del_trace_kprobe_event(int fd, struct str_node *ent)
+{
+	char *p;
+	char buf[128];
+
+	/* Convert from perf-probe event to trace-kprobe event */
+	if (e_snprintf(buf, 128, "-:%s", ent->s) < 0)
+		die("Failed to copy event.");
+	p = strchr(buf + 2, ':');
+	if (!p)
+		die("Internal error: %s should have ':' but not.", ent->s);
+	*p = '/';
+
+	write_trace_kprobe_event(fd, buf);
+	printf("Remove event: %s\n", ent->s);
+}
+
 static void del_trace_kprobe_event(int fd, const char *group,
 				   const char *event, struct strlist *namelist)
 {
 	char buf[128];
-	struct str_node *ent;
+	struct str_node *ent, *n;
+	int found = 0;
 
 	if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
 		die("Failed to copy event.");
-	ent = strlist__find(namelist, buf);
-	if (!ent) {
+
+	if (strpbrk(buf, "*?")) { /* Glob-exp */
+		strlist__for_each_safe(ent, n, namelist)
+			if (strglobmatch(ent->s, buf)) {
+				found++;
+				__del_trace_kprobe_event(fd, ent);
+				strlist__remove(namelist, ent);
+			}
+	} else {
+		ent = strlist__find(namelist, buf);
+		if (ent) {
+			found++;
+			__del_trace_kprobe_event(fd, ent);
+			strlist__remove(namelist, ent);
+		}
+	}
+	if (found == 0)
 		pr_info("Info: event \"%s\" does not exist."
 			" Could not remove it.\n", buf);
-		return;
-	}
-	/* Convert from perf-probe event to trace-kprobe event */
-	if (e_snprintf(buf, 128, "-:%s/%s", group, event) < 0)
-		die("Failed to copy event.");
-
-	write_trace_kprobe_event(fd, buf);
-	printf("Remove event: %s:%s\n", group, event);
-	strlist__remove(namelist, ent);
 }
 
 void del_trace_kprobe_events(struct strlist *dellist)
@@ -571,15 +595,17 @@ void del_trace_kprobe_events(struct strlist *dellist)
 		str = strdup(ent->s);
 		if (!str)
 			die("Failed to copy event.");
+		pr_debug("Parsing: %s\n", str);
 		p = strchr(str, ':');
 		if (p) {
 			group = str;
 			*p = '\0';
 			event = p + 1;
 		} else {
-			group = PERFPROBE_GROUP;
+			group = "*";
 			event = str;
 		}
+		pr_debug("Group: %s, Event: %s\n", group, event);
 		del_trace_kprobe_event(fd, group, event, namelist);
 		free(str);
 	}
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index f24a8cc..5352d7d 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -226,3 +226,28 @@ fail:
 	argv_free(argv);
 	return NULL;
 }
+
+/* Glob expression pattern matching */
+bool strglobmatch(const char *str, const char *pat)
+{
+	while (*str && *pat && *pat != '*') {
+		if (*pat == '?') {
+			str++;
+			pat++;
+		} else
+			if (*str++ != *pat++)
+				return false;
+	}
+	/* Check wild card */
+	if (*pat == '*') {
+		while (*pat == '*')
+			pat++;
+		if (!*pat)	/* Tail wild card matches all */
+			return true;
+		while (*str)
+			if (strglobmatch(str++, pat))
+				return true;
+	}
+	return !*str && !*pat;
+}
+
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h
index bfecec2..02ede58 100644
--- a/tools/perf/util/string.h
+++ b/tools/perf/util/string.h
@@ -1,6 +1,7 @@
 #ifndef __PERF_STRING_H_
 #define __PERF_STRING_H_
 
+#include <stdbool.h>
 #include "types.h"
 
 int hex2u64(const char *ptr, u64 *val);
@@ -8,6 +9,7 @@ char *strxfrchar(char *s, char from, char to);
 s64 perf_atoll(const char *str);
 char **argv_split(const char *str, int *argcp);
 void argv_free(char **argv);
+bool strglobmatch(const char *str, const char *pat);
 
 #define _STR(x) #x
 #define STR(x) _STR(x)


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 06/14] perf probe: Fix --del to update current event list
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (5 preceding siblings ...)
  2009-12-15 15:27 ` [PATCH -tip 07/14] perf tools: Add for_each macros for strlist Masami Hiramatsu
@ 2009-12-15 15:27 ` Masami Hiramatsu
  2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:27 ` [PATCH -tip 03/14] perf probe: Check hyphen only argument Masami Hiramatsu
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:27 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Fix --del option to update current existing event list
after perf probe deleted an event.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/util/probe-event.c |    5 ++++-
 tools/perf/util/strlist.c     |    6 +++---
 tools/perf/util/strlist.h     |    7 ++++++-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d733bfa..4055d01 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -540,10 +540,12 @@ static void del_trace_kprobe_event(int fd, const char *group,
 				   const char *event, struct strlist *namelist)
 {
 	char buf[128];
+	struct str_node *ent;
 
 	if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
 		die("Failed to copy event.");
-	if (!strlist__has_entry(namelist, buf)) {
+	ent = strlist__find(namelist, buf);
+	if (!ent) {
 		pr_info("Info: event \"%s\" does not exist."
 			" Could not remove it.\n", buf);
 		return;
@@ -554,6 +556,7 @@ static void del_trace_kprobe_event(int fd, const char *group,
 
 	write_trace_kprobe_event(fd, buf);
 	printf("Remove event: %s:%s\n", group, event);
+	strlist__remove(namelist, ent);
 }
 
 void del_trace_kprobe_events(struct strlist *dellist)
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
index 7ad3817..6783a20 100644
--- a/tools/perf/util/strlist.c
+++ b/tools/perf/util/strlist.c
@@ -102,7 +102,7 @@ void strlist__remove(struct strlist *self, struct str_node *sn)
 	str_node__delete(sn, self->dupstr);
 }
 
-bool strlist__has_entry(struct strlist *self, const char *entry)
+struct str_node *strlist__find(struct strlist *self, const char *entry)
 {
 	struct rb_node **p = &self->entries.rb_node;
 	struct rb_node *parent = NULL;
@@ -120,10 +120,10 @@ bool strlist__has_entry(struct strlist *self, const char *entry)
 		else if (rc < 0)
 			p = &(*p)->rb_right;
 		else
-			return true;
+			return sn;
 	}
 
-	return false;
+	return NULL;
 }
 
 static int strlist__parse_list_entry(struct strlist *self, const char *s)
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
index cb46593..59091c7 100644
--- a/tools/perf/util/strlist.h
+++ b/tools/perf/util/strlist.h
@@ -23,7 +23,12 @@ int strlist__load(struct strlist *self, const char *filename);
 int strlist__add(struct strlist *self, const char *str);
 
 struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
-bool strlist__has_entry(struct strlist *self, const char *entry);
+struct str_node *strlist__find(struct strlist *self, const char *entry);
+
+static inline bool strlist__has_entry(struct strlist *self, const char *entry)
+{
+	return strlist__find(self, entry) != NULL;
+}
 
 static inline bool strlist__empty(const struct strlist *self)
 {


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 05/14] perf probe: Fix --del to show info instead of  warning
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (2 preceding siblings ...)
  2009-12-15 15:27 ` [PATCH -tip 09/14] perf probe: Add glob matching support on --del Masami Hiramatsu
@ 2009-12-15 15:27 ` Masami Hiramatsu
  2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:27 ` [PATCH -tip 04/14] perf probe: Show need-dwarf message only if it is really needed Masami Hiramatsu
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:27 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Fix --del option to show info message instead of warning
if failing to find specified event.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/util/probe-event.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 1653a62..d733bfa 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -544,7 +544,8 @@ static void del_trace_kprobe_event(int fd, const char *group,
 	if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
 		die("Failed to copy event.");
 	if (!strlist__has_entry(namelist, buf)) {
-		pr_warning("Warning: event \"%s\" is not found.\n", buf);
+		pr_info("Info: event \"%s\" does not exist."
+			" Could not remove it.\n", buf);
 		return;
 	}
 	/* Convert from perf-probe event to trace-kprobe event */


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 04/14] perf probe: Show need-dwarf message only if it is  really needed
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (3 preceding siblings ...)
  2009-12-15 15:27 ` [PATCH -tip 05/14] perf probe: Fix --del to show info instead of warning Masami Hiramatsu
@ 2009-12-15 15:27 ` Masami Hiramatsu
  2009-12-15 19:27   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:27 ` [PATCH -tip 07/14] perf tools: Add for_each macros for strlist Masami Hiramatsu
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:27 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Show need-dwarf message only if the probe is really requires
debuginfo analysis. This also use pr_debug for debugging message
instead of pr_warning.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/builtin-probe.c     |   20 +++++++++++++-------
 tools/perf/util/probe-finder.c |    4 +---
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 919037b..7f35709 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -261,15 +261,21 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 
 		lseek(fd, SEEK_SET, 0);
 		ret = find_probepoint(fd, pp);
-		if (ret < 0) {
-			if (session.need_dwarf)
-				die("Could not analyze debuginfo.");
-
-			pr_warning("An error occurred in debuginfo analysis. Try to use symbols.\n");
-			break;
-		}
+		if (ret > 0)
+			continue;
 		if (ret == 0)	/* No error but failed to find probe point. */
 			die("No probe point found.");
+		/* Error path */
+		if (session.need_dwarf) {
+			if (ret == -ENOENT)
+				pr_warning("No dwarf info found in the vmlinux"
+					   " - please rebuild with "
+					   "CONFIG_DEBUG_INFO.\n");
+			die("Could not analyze debuginfo.");
+		}
+		pr_debug("An error occurred in debuginfo analysis."
+			 " Try to use symbols.\n");
+		break;
 	}
 	close(fd);
 
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 4585f1d..4b852c0 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -687,10 +687,8 @@ int find_probepoint(int fd, struct probe_point *pp)
 	struct probe_finder pf = {.pp = pp};
 
 	ret = dwarf_init(fd, DW_DLC_READ, 0, 0, &__dw_debug, &__dw_error);
-	if (ret != DW_DLV_OK) {
-		pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO.\n");
+	if (ret != DW_DLV_OK)
 		return -ENOENT;
-	}
 
 	pp->found = 0;
 	while (++cu_number) {


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 07/14] perf tools: Add for_each macros for strlist
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (4 preceding siblings ...)
  2009-12-15 15:27 ` [PATCH -tip 04/14] perf probe: Show need-dwarf message only if it is really needed Masami Hiramatsu
@ 2009-12-15 15:27 ` Masami Hiramatsu
  2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:27 ` [PATCH -tip 06/14] perf probe: Fix --del to update current event list Masami Hiramatsu
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:27 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Add for_each iteration macros for strlist. This patch
introduces strlist__for_each() and strlist__for_each_safe(),
both are similar to list_for_each() and list_for_each_safe().

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/util/strlist.h |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
index 59091c7..3ba8390 100644
--- a/tools/perf/util/strlist.h
+++ b/tools/perf/util/strlist.h
@@ -40,5 +40,39 @@ static inline unsigned int strlist__nr_entries(const struct strlist *self)
 	return self->nr_entries;
 }
 
+/* For strlist iteration */
+static inline struct str_node *strlist__first(struct strlist *self)
+{
+	struct rb_node *rn = rb_first(&self->entries);
+	return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
+}
+static inline struct str_node *strlist__next(struct str_node *sn)
+{
+	struct rb_node *rn;
+	if (!sn)
+		return NULL;
+	rn = rb_next(&sn->rb_node);
+	return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
+}
+
+/**
+ * strlist_for_each      - iterate over a strlist
+ * @pos:	the &struct str_node to use as a loop cursor.
+ * @self:	the &struct strlist for loop.
+ */
+#define strlist__for_each(pos, self)	\
+	for (pos = strlist__first(self); pos; pos = strlist__next(pos))
+
+/**
+ * strlist_for_each_safe - iterate over a strlist safe against removal of
+ *                         str_node
+ * @pos:	the &struct str_node to use as a loop cursor.
+ * @n:		another &struct str_node to use as temporary storage.
+ * @self:	the &struct strlist for loop.
+ */
+#define strlist__for_each_safe(pos, n, self)	\
+	for (pos = strlist__first(self), n = strlist__next(pos); pos;\
+	     pos = n, n = strlist__next(n))
+
 int strlist__parse_list(struct strlist *self, const char *s);
 #endif /* __PERF_STRLIST_H */


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 12/14] perf probe: Check build-id of vmlinux
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (10 preceding siblings ...)
  2009-12-15 15:28 ` [PATCH -tip 14/14] perf probe: Fix to show which probe point is not found Masami Hiramatsu
@ 2009-12-15 15:28 ` Masami Hiramatsu
  2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:28 ` [PATCH -tip 11/14] perf probe: Reject second attempt of adding same-name event Masami Hiramatsu
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:28 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Check build-id of vmlinux by using functions in symbol.c.
This also exposes map__load() for getting vmlinux path,
and removes vmlinux path list in builtin-probe.c,
because symbol.c already has that. Checking build-id
prevents users to open old or different debuginfo from
current running kernel.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/builtin-probe.c |   72 ++++++++++++++++++--------------------------
 tools/perf/util/event.h    |    2 +
 tools/perf/util/map.c      |   14 ++++++---
 3 files changed, 41 insertions(+), 47 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 4d232cb..5008605 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -38,33 +38,27 @@
 #include "util/strlist.h"
 #include "util/event.h"
 #include "util/debug.h"
+#include "util/symbol.h"
+#include "util/thread.h"
+#include "util/session.h"
 #include "util/parse-options.h"
 #include "util/parse-events.h"	/* For debugfs_path */
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
 
-/* Default vmlinux search paths */
-#define NR_SEARCH_PATH 4
-const char *default_search_path[NR_SEARCH_PATH] = {
-"/lib/modules/%s/build/vmlinux",		/* Custom build kernel */
-"/usr/lib/debug/lib/modules/%s/vmlinux",	/* Red Hat debuginfo */
-"/boot/vmlinux-debug-%s",			/* Ubuntu */
-"./vmlinux",					/* CWD */
-};
-
 #define MAX_PATH_LEN 256
 #define MAX_PROBES 128
 
 /* Session management structure */
 static struct {
-	char *vmlinux;
-	char *release;
 	bool need_dwarf;
 	bool list_events;
 	bool force_add;
 	int nr_probe;
 	struct probe_point probes[MAX_PROBES];
 	struct strlist *dellist;
+	struct symbol_conf conf;
+	struct perf_session *psession;
 } session;
 
 
@@ -122,33 +116,21 @@ static int opt_del_probe_event(const struct option *opt __used,
 }
 
 #ifndef NO_LIBDWARF
-static int open_default_vmlinux(void)
+static int open_vmlinux(void)
 {
-	struct utsname uts;
-	char fname[MAX_PATH_LEN];
-	int fd, ret, i;
-
-	ret = uname(&uts);
-	if (ret) {
-		pr_debug("uname() failed.\n");
-		return -errno;
+	struct map *kmap;
+	kmap = map_groups__find_by_name(&session.psession->kmaps,
+					MAP__FUNCTION, "[kernel.kallsyms]");
+	if (!kmap) {
+		pr_debug("Could not find kernel map.\n");
+		return -ENOENT;
 	}
-	session.release = uts.release;
-	for (i = 0; i < NR_SEARCH_PATH; i++) {
-		ret = snprintf(fname, MAX_PATH_LEN,
-			       default_search_path[i], session.release);
-		if (ret >= MAX_PATH_LEN || ret < 0) {
-			pr_debug("Filename(%d,%s) is too long.\n", i,
-				uts.release);
-			errno = E2BIG;
-			return -E2BIG;
-		}
-		pr_debug("try to open %s\n", fname);
-		fd = open(fname, O_RDONLY);
-		if (fd >= 0)
-			break;
+	if (map__load(kmap, session.psession, NULL) < 0) {
+		pr_debug("Failed to load kernel map.\n");
+		return -EINVAL;
 	}
-	return fd;
+	pr_debug("Try to open %s\n", kmap->dso->long_name);
+	return open(kmap->dso->long_name, O_RDONLY);
 }
 #endif
 
@@ -164,8 +146,8 @@ static const struct option options[] = {
 	OPT_BOOLEAN('v', "verbose", &verbose,
 		    "be more verbose (show parsed arguments, etc)"),
 #ifndef NO_LIBDWARF
-	OPT_STRING('k', "vmlinux", &session.vmlinux, "file",
-		"vmlinux/module pathname"),
+	OPT_STRING('k', "vmlinux", &session.conf.vmlinux_name,
+		   "file", "vmlinux pathname"),
 #endif
 	OPT_BOOLEAN('l', "list", &session.list_events,
 		    "list up current probe events"),
@@ -236,17 +218,23 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 			return 0;
 	}
 
+	/* Initialize symbol maps for vmlinux */
+	if (session.conf.vmlinux_name == NULL)
+		session.conf.try_vmlinux_path = true;
+	if (symbol__init(&session.conf) < 0)
+		die("Failed to init symbol map.");
+	session.psession = perf_session__new(NULL, O_WRONLY, false,
+					     &session.conf);
+	if (session.psession == NULL)
+		die("Failed to init perf_session.");
+
 	if (session.need_dwarf)
 #ifdef NO_LIBDWARF
 		die("Debuginfo-analysis is not supported");
 #else	/* !NO_LIBDWARF */
 		pr_debug("Some probes require debuginfo.\n");
 
-	if (session.vmlinux) {
-		pr_debug("Try to open %s.", session.vmlinux);
-		fd = open(session.vmlinux, O_RDONLY);
-	} else
-		fd = open_default_vmlinux();
+	fd = open_vmlinux();
 	if (fd < 0) {
 		if (session.need_dwarf)
 			die("Could not open debuginfo file.");
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index a92e0b0..8027309 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -152,6 +152,8 @@ size_t map__fprintf(struct map *self, FILE *fp);
 
 struct perf_session;
 
+int map__load(struct map *self, struct perf_session *session,
+	      symbol_filter_t filter);
 struct symbol *map__find_symbol(struct map *self, struct perf_session *session,
 				u64 addr, symbol_filter_t filter);
 struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 8b3dd46..c4d55a0 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -104,12 +104,16 @@ void map__fixup_end(struct map *self)
 
 #define DSO__DELETED "(deleted)"
 
-static int map__load(struct map *self, struct perf_session *session,
-		     symbol_filter_t filter)
+int map__load(struct map *self, struct perf_session *session,
+	      symbol_filter_t filter)
 {
 	const char *name = self->dso->long_name;
-	int nr = dso__load(self->dso, self, session, filter);
+	int nr;
 
+	if (dso__loaded(self->dso, self->type))
+		return 0;
+
+	nr = dso__load(self->dso, self, session, filter);
 	if (nr < 0) {
 		if (self->dso->has_build_id) {
 			char sbuild_id[BUILD_ID_SIZE * 2 + 1];
@@ -147,7 +151,7 @@ static int map__load(struct map *self, struct perf_session *session,
 struct symbol *map__find_symbol(struct map *self, struct perf_session *session,
 				u64 addr, symbol_filter_t filter)
 {
-	if (!dso__loaded(self->dso, self->type) && map__load(self, session, filter) < 0)
+	if (map__load(self, session, filter) < 0)
 		return NULL;
 
 	return dso__find_symbol(self->dso, self->type, addr);
@@ -157,7 +161,7 @@ struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
 					struct perf_session *session,
 					symbol_filter_t filter)
 {
-	if (!dso__loaded(self->dso, self->type) && map__load(self, session, filter) < 0)
+	if (map__load(self, session, filter) < 0)
 		return NULL;
 
 	if (!dso__sorted_by_name(self->dso, self->type))


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 10/14] perf probe: Support event name for --add option
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (8 preceding siblings ...)
  2009-12-15 15:27 ` [PATCH -tip 08/14] perf probe: Use strlist__for_each macros in probe-event.c Masami Hiramatsu
@ 2009-12-15 15:28 ` Masami Hiramatsu
  2009-12-15 19:54   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:28 ` [PATCH -tip 14/14] perf probe: Fix to show which probe point is not found Masami Hiramatsu
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:28 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Support event name syntax for --add option. This allows
users to specify event name for each new event.
The --add syntax is:
 perf probe --add '[EVENT=]SRC:LINE ARGS'
or
 perf probe --add '[EVENT=]FUNC[+OFFS|%return|:RLN][@SRC] ARGS'

e.g.

 ./perf probe --add myprobe1=schedule

Note: currently group name is not supported yet, because it
can cause name-space confliction with other tracepoint/
hw-breakpoint events.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/Documentation/perf-probe.txt |    3 +
 tools/perf/builtin-probe.c              |    8 ++-
 tools/perf/util/probe-event.c           |   74 +++++++++++++++++++------------
 tools/perf/util/probe-event.h           |    3 -
 tools/perf/util/probe-finder.h          |    3 +
 5 files changed, 55 insertions(+), 36 deletions(-)

diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 8fa6bf9..250e391 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -49,8 +49,9 @@ PROBE SYNTAX
 ------------
 Probe points are defined by following syntax.
 
- "FUNC[+OFFS|:RLN|%return][@SRC]|SRC:ALN [ARG ...]"
+ "[EVENT=]FUNC[+OFFS|:RLN|%return][@SRC]|SRC:ALN [ARG ...]"
 
+'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'.
 'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, 'RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. In addition, 'SRC' specifies a source file which has that function.
 It is also possible to specify a probe point by the source line number by using 'SRC:ALN' syntax, where 'SRC' is the source file path and 'ALN' is the line number.
 'ARG' specifies the arguments of this probe point. You can use the name of local variable, or kprobe-tracer argument format (e.g. $retval, %ax, etc).
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 7f35709..4f768f3 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -172,13 +172,13 @@ static const struct option options[] = {
 		opt_del_probe_event),
 	OPT_CALLBACK('a', "add", NULL,
 #ifdef NO_LIBDWARF
-		"FUNC[+OFFS|%return] [ARG ...]",
+		"[EVENT=]FUNC[+OFFS|%return] [ARG ...]",
 #else
-		"FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]",
+		"[EVENT=]FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]",
 #endif
 		"probe point definition, where\n"
-		"\t\tGRP:\tGroup name (optional)\n"
-		"\t\tNAME:\tEvent name\n"
+		"\t\tGROUP:\tGroup name (optional)\n"
+		"\t\tEVENT:\tEvent name\n"
 		"\t\tFUNC:\tFunction name\n"
 		"\t\tOFFS:\tOffset from function entry (in byte)\n"
 		"\t\t%return:\tPut the probe at function return\n"
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index af7cc76..0b769bc 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -69,10 +69,23 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
 	char c, nc = 0;
 	/*
 	 * <Syntax>
-	 * perf probe SRC:LN
-	 * perf probe FUNC[+OFFS|%return][@SRC]
+	 * perf probe [EVENT=]SRC:LN
+	 * perf probe [EVENT=]FUNC[+OFFS|%return][@SRC]
+	 *
+	 * TODO:Group name support
 	 */
 
+	ptr = strchr(arg, '=');
+	if (ptr) {	/* Event name */
+		*ptr = '\0';
+		tmp = ptr + 1;
+		ptr = strchr(arg, ':');
+		if (ptr)	/* Group name is not supported yet. */
+			semantic_error("Group name is not supported yet.");
+		pp->event = strdup(arg);
+		arg = tmp;
+	}
+
 	ptr = strpbrk(arg, ":+@%");
 	if (ptr) {
 		nc = *ptr;
@@ -188,8 +201,7 @@ void parse_perf_probe_event(const char *str, struct probe_point *pp,
 }
 
 /* Parse kprobe_events event into struct probe_point */
-void parse_trace_kprobe_event(const char *str, char **group, char **event,
-			      struct probe_point *pp)
+void parse_trace_kprobe_event(const char *str, struct probe_point *pp)
 {
 	char pr;
 	char *p;
@@ -205,18 +217,17 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,
 
 	/* Scan event and group name. */
 	ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]",
-		     &pr, (float *)(void *)group, (float *)(void *)event);
+		     &pr, (float *)(void *)&pp->group,
+		     (float *)(void *)&pp->event);
 	if (ret != 3)
 		semantic_error("Failed to parse event name: %s", argv[0]);
-	pr_debug("Group:%s Event:%s probe:%c\n", *group, *event, pr);
-
-	if (!pp)
-		goto end;
+	pr_debug("Group:%s Event:%s probe:%c\n", pp->group, pp->event, pr);
 
 	pp->retprobe = (pr == 'r');
 
 	/* Scan function name and offset */
-	ret = sscanf(argv[1], "%a[^+]+%d", (float *)(void *)&pp->function, &pp->offset);
+	ret = sscanf(argv[1], "%a[^+]+%d", (float *)(void *)&pp->function,
+		     &pp->offset);
 	if (ret == 1)
 		pp->offset = 0;
 
@@ -235,7 +246,6 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,
 			die("Failed to copy argument.");
 	}
 
-end:
 	argv_free(argv);
 }
 
@@ -368,6 +378,10 @@ static void clear_probe_point(struct probe_point *pp)
 {
 	int i;
 
+	if (pp->event)
+		free(pp->event);
+	if (pp->group)
+		free(pp->group);
 	if (pp->function)
 		free(pp->function);
 	if (pp->file)
@@ -382,13 +396,13 @@ static void clear_probe_point(struct probe_point *pp)
 }
 
 /* Show an event */
-static void show_perf_probe_event(const char *group, const char *event,
-				  const char *place, struct probe_point *pp)
+static void show_perf_probe_event(const char *event, const char *place,
+				  struct probe_point *pp)
 {
 	int i, ret;
 	char buf[128];
 
-	ret = e_snprintf(buf, 128, "%s:%s", group, event);
+	ret = e_snprintf(buf, 128, "%s:%s", pp->group, event);
 	if (ret < 0)
 		die("Failed to copy event: %s", strerror(-ret));
 	printf("  %-40s (on %s", buf, place);
@@ -405,7 +419,6 @@ static void show_perf_probe_event(const char *group, const char *event,
 void show_perf_probe_events(void)
 {
 	int fd, nr;
-	char *group, *event;
 	struct probe_point pp;
 	struct strlist *rawlist;
 	struct str_node *ent;
@@ -415,16 +428,14 @@ void show_perf_probe_events(void)
 	close(fd);
 
 	strlist__for_each(ent, rawlist) {
-		parse_trace_kprobe_event(ent->s, &group, &event, &pp);
+		parse_trace_kprobe_event(ent->s, &pp);
 		/* Synthesize only event probe point */
 		nr = pp.nr_args;
 		pp.nr_args = 0;
 		synthesize_perf_probe_event(&pp);
 		pp.nr_args = nr;
 		/* Show an event */
-		show_perf_probe_event(group, event, pp.probes[0], &pp);
-		free(group);
-		free(event);
+		show_perf_probe_event(pp.event, pp.probes[0], &pp);
 		clear_probe_point(&pp);
 	}
 
@@ -434,24 +445,25 @@ void show_perf_probe_events(void)
 /* Get current perf-probe event names */
 static struct strlist *get_perf_event_names(int fd, bool include_group)
 {
-	char *group, *event;
 	char buf[128];
 	struct strlist *sl, *rawlist;
 	struct str_node *ent;
+	struct probe_point pp;
 
+	memset(&pp, 0, sizeof(pp));
 	rawlist = get_trace_kprobe_event_rawlist(fd);
 
 	sl = strlist__new(true, NULL);
 	strlist__for_each(ent, rawlist) {
-		parse_trace_kprobe_event(ent->s, &group, &event, NULL);
+		parse_trace_kprobe_event(ent->s, &pp);
 		if (include_group) {
-			if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
+			if (e_snprintf(buf, 128, "%s:%s", pp.group,
+				       pp.event) < 0)
 				die("Failed to copy group:event name.");
 			strlist__add(sl, buf);
 		} else
-			strlist__add(sl, event);
-		free(group);
-		free(event);
+			strlist__add(sl, pp.event);
+		clear_probe_point(&pp);
 	}
 
 	strlist__delete(rawlist);
@@ -507,19 +519,23 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 
 	for (j = 0; j < nr_probes; j++) {
 		pp = probes + j;
+		if (!pp->event)
+			pp->event = strdup(pp->function);
+		if (!pp->group)
+			pp->group = strdup(PERFPROBE_GROUP);
+		DIE_IF(!pp->event || !pp->group);
 		for (i = 0; i < pp->found; i++) {
 			/* Get an unused new event name */
-			get_new_event_name(event, 64, pp->function, namelist);
+			get_new_event_name(event, 64, pp->event, namelist);
 			snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n",
 				 pp->retprobe ? 'r' : 'p',
-				 PERFPROBE_GROUP, event,
+				 pp->group, event,
 				 pp->probes[i]);
 			write_trace_kprobe_event(fd, buf);
 			printf("Added new event:\n");
 			/* Get the first parameter (probe-point) */
 			sscanf(pp->probes[i], "%s", buf);
-			show_perf_probe_event(PERFPROBE_GROUP, event,
-					      buf, pp);
+			show_perf_probe_event(event, buf, pp);
 			/* Add added event name to namelist */
 			strlist__add(namelist, event);
 		}
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 028575b..8bb22f5 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -8,8 +8,7 @@
 extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
 				   bool *need_dwarf);
 extern int synthesize_perf_probe_event(struct probe_point *pp);
-extern void parse_trace_kprobe_event(const char *str, char **group,
-				     char **event, struct probe_point *pp);
+extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
 extern int synthesize_trace_kprobe_event(struct probe_point *pp);
 extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes);
 extern void del_trace_kprobe_events(struct strlist *dellist);
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index bdebca6..5e4050c 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -12,6 +12,9 @@ static inline int is_c_varname(const char *name)
 }
 
 struct probe_point {
+	char	*event;		/* Event name */
+	char	*group;		/* Event group */
+
 	/* Inputs */
 	char	*file;		/* File name */
 	int	line;		/* Line number */


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 13/14] perf probe: Check symbols in symtab/kallsyms
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (12 preceding siblings ...)
  2009-12-15 15:28 ` [PATCH -tip 11/14] perf probe: Reject second attempt of adding same-name event Masami Hiramatsu
@ 2009-12-15 15:28 ` Masami Hiramatsu
  2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 19:23 ` [PATCH -tip 00/14] perf-probe updates Ingo Molnar
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:28 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Check symbols in symtab/kallsyms when no debuginfo
is available.

e.g.

# perf probe test
  Fatal: Kernel symbol 'test' not found - probe not added.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/builtin-probe.c |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 5008605..f019536 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -59,6 +59,7 @@ static struct {
 	struct strlist *dellist;
 	struct symbol_conf conf;
 	struct perf_session *psession;
+	struct map *kmap;
 } session;
 
 
@@ -115,22 +116,26 @@ static int opt_del_probe_event(const struct option *opt __used,
 	return 0;
 }
 
+/* Currently just checking function name from symbol map */
+static void evaluate_probe_point(struct probe_point *pp)
+{
+	struct symbol *sym;
+	sym = map__find_symbol_by_name(session.kmap, pp->function,
+				       session.psession, NULL);
+	if (!sym)
+		die("Kernel symbol \'%s\' not found - probe not added.",
+		    pp->function);
+}
+
 #ifndef NO_LIBDWARF
 static int open_vmlinux(void)
 {
-	struct map *kmap;
-	kmap = map_groups__find_by_name(&session.psession->kmaps,
-					MAP__FUNCTION, "[kernel.kallsyms]");
-	if (!kmap) {
-		pr_debug("Could not find kernel map.\n");
-		return -ENOENT;
-	}
-	if (map__load(kmap, session.psession, NULL) < 0) {
+	if (map__load(session.kmap, session.psession, NULL) < 0) {
 		pr_debug("Failed to load kernel map.\n");
 		return -EINVAL;
 	}
-	pr_debug("Try to open %s\n", kmap->dso->long_name);
-	return open(kmap->dso->long_name, O_RDONLY);
+	pr_debug("Try to open %s\n", session.kmap->dso->long_name);
+	return open(session.kmap->dso->long_name, O_RDONLY);
 }
 #endif
 
@@ -219,6 +224,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 	}
 
 	/* Initialize symbol maps for vmlinux */
+	session.conf.sort_by_name = true;
 	if (session.conf.vmlinux_name == NULL)
 		session.conf.try_vmlinux_path = true;
 	if (symbol__init(&session.conf) < 0)
@@ -227,6 +233,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 					     &session.conf);
 	if (session.psession == NULL)
 		die("Failed to init perf_session.");
+	session.kmap = map_groups__find_by_name(&session.psession->kmaps,
+						MAP__FUNCTION,
+						"[kernel.kallsyms]");
+	if (!session.kmap)
+		die("Could not find kernel map.\n");
 
 	if (session.need_dwarf)
 #ifdef NO_LIBDWARF
@@ -279,6 +290,7 @@ end_dwarf:
 		if (pp->found)	/* This probe is already found. */
 			continue;
 
+		evaluate_probe_point(pp);
 		ret = synthesize_trace_kprobe_event(pp);
 		if (ret == -E2BIG)
 			die("probe point definition becomes too long.");


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 14/14] perf probe: Fix to show which probe point is not  found
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (9 preceding siblings ...)
  2009-12-15 15:28 ` [PATCH -tip 10/14] perf probe: Support event name for --add option Masami Hiramatsu
@ 2009-12-15 15:28 ` Masami Hiramatsu
  2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:28 ` [PATCH -tip 12/14] perf probe: Check build-id of vmlinux Masami Hiramatsu
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:28 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Fix perf probe to show which probe point is not found.
With out this patch, it shows just "No probe point found."
This doesn't help users if they specify several probes.
e.g.

# perf probe -f --add schedule --add test
  Fatal: No probe point found.

This patch makes error message more helpful as below.

# perf probe --add schedule --add test
  Fatal: Probe point 'test' not found. - probe not added.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/builtin-probe.c    |    7 +++++--
 tools/perf/util/probe-event.c |   34 ++++++++++++++++++++++++----------
 tools/perf/util/probe-event.h |    1 +
 3 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index f019536..beb49e3 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -265,8 +265,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 		ret = find_probepoint(fd, pp);
 		if (ret > 0)
 			continue;
-		if (ret == 0)	/* No error but failed to find probe point. */
-			die("No probe point found.");
+		if (ret == 0) {	/* No error but failed to find probe point. */
+			synthesize_perf_probe_point(pp);
+			die("Probe point '%s' not found. - probe not added.",
+			    pp->probes[0]);
+		}
 		/* Error path */
 		if (session.need_dwarf) {
 			if (ret == -ENOENT)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index e74ecfc..3c2e743 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -249,11 +249,12 @@ void parse_trace_kprobe_event(const char *str, struct probe_point *pp)
 	argv_free(argv);
 }
 
-int synthesize_perf_probe_event(struct probe_point *pp)
+/* Synthesize only probe point (not argument) */
+int synthesize_perf_probe_point(struct probe_point *pp)
 {
 	char *buf;
 	char offs[64] = "", line[64] = "";
-	int i, len, ret;
+	int ret;
 
 	pp->probes[0] = buf = zalloc(MAX_CMDLEN);
 	if (!buf)
@@ -274,10 +275,24 @@ int synthesize_perf_probe_event(struct probe_point *pp)
 				 offs, pp->retprobe ? "%return" : "", line);
 	else
 		ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", pp->file, line);
-	if (ret <= 0)
-		goto error;
-	len = ret;
+	if (ret <= 0) {
+error:
+		free(pp->probes[0]);
+		pp->probes[0] = NULL;
+	}
+	return ret;
+}
+
+int synthesize_perf_probe_event(struct probe_point *pp)
+{
+	char *buf;
+	int i, len, ret;
 
+	len = synthesize_perf_probe_point(pp);
+	if (len < 0)
+		return 0;
+
+	buf = pp->probes[0];
 	for (i = 0; i < pp->nr_args; i++) {
 		ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
 				 pp->args[i]);
@@ -290,6 +305,7 @@ int synthesize_perf_probe_event(struct probe_point *pp)
 	return pp->found;
 error:
 	free(pp->probes[0]);
+	pp->probes[0] = NULL;
 
 	return ret;
 }
@@ -319,6 +335,7 @@ int synthesize_trace_kprobe_event(struct probe_point *pp)
 	return pp->found;
 error:
 	free(pp->probes[0]);
+	pp->probes[0] = NULL;
 
 	return ret;
 }
@@ -418,7 +435,7 @@ static void show_perf_probe_event(const char *event, const char *place,
 /* List up current perf-probe events */
 void show_perf_probe_events(void)
 {
-	int fd, nr;
+	int fd;
 	struct probe_point pp;
 	struct strlist *rawlist;
 	struct str_node *ent;
@@ -430,10 +447,7 @@ void show_perf_probe_events(void)
 	strlist__for_each(ent, rawlist) {
 		parse_trace_kprobe_event(ent->s, &pp);
 		/* Synthesize only event probe point */
-		nr = pp.nr_args;
-		pp.nr_args = 0;
-		synthesize_perf_probe_event(&pp);
-		pp.nr_args = nr;
+		synthesize_perf_probe_point(&pp);
 		/* Show an event */
 		show_perf_probe_event(pp.event, pp.probes[0], &pp);
 		clear_probe_point(&pp);
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 8fd3052..7f1d499 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -7,6 +7,7 @@
 
 extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
 				   bool *need_dwarf);
+extern int synthesize_perf_probe_point(struct probe_point *pp);
 extern int synthesize_perf_probe_event(struct probe_point *pp);
 extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
 extern int synthesize_trace_kprobe_event(struct probe_point *pp);


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* [PATCH -tip 11/14] perf probe: Reject second attempt of adding  same-name event
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (11 preceding siblings ...)
  2009-12-15 15:28 ` [PATCH -tip 12/14] perf probe: Check build-id of vmlinux Masami Hiramatsu
@ 2009-12-15 15:28 ` Masami Hiramatsu
  2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
  2009-12-15 15:28 ` [PATCH -tip 13/14] perf probe: Check symbols in symtab/kallsyms Masami Hiramatsu
  2009-12-15 19:23 ` [PATCH -tip 00/14] perf-probe updates Ingo Molnar
  14 siblings, 1 reply; 30+ messages in thread
From: Masami Hiramatsu @ 2009-12-15 15:28 UTC (permalink / raw)
  To: Ingo Molnar, Frederic Weisbecker, lkml
  Cc: Paul Mackerras, Arnaldo Carvalho de Melo, Steven Rostedt,
	Jim Keniston, Ananth N Mavinakayanahalli, Christoph Hellwig,
	Frank Ch. Eigler, Jason Baron, K.Prasad, Peter Zijlstra,
	Srikar Dronamraju, systemtap, DLE

Reject second attempt of adding same-name event. This patch
also provides --force option which allows user to add additional
probe events on the same-name event.

e.g.
(the first attempt : success)
 ./perf probe schedule
 Added new event:
   probe:schedule                           (on schedule+0)

(the second attempt : failure)
 ./perf probe schedule:11
 Error: event "schedule" already exists. (Use -f to force duplicates.)
   Fatal: Can't add new event.

(the second attempt with -f : successfully added)
 ./perf probe -f schedule:11
 Added new event:
   probe:schedule_1                         (on schedule+45)

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---

 tools/perf/builtin-probe.c    |    6 +++++-
 tools/perf/util/probe-event.c |   24 +++++++++++++++++++++---
 tools/perf/util/probe-event.h |    3 ++-
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 4f768f3..4d232cb 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -61,6 +61,7 @@ static struct {
 	char *release;
 	bool need_dwarf;
 	bool list_events;
+	bool force_add;
 	int nr_probe;
 	struct probe_point probes[MAX_PROBES];
 	struct strlist *dellist;
@@ -192,6 +193,8 @@ static const struct option options[] = {
 #endif
 		"\t\t\tkprobe-tracer argument format.)\n",
 		opt_add_probe_event),
+	OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events"
+		    " with existing name"),
 	OPT_END()
 };
 
@@ -296,7 +299,8 @@ end_dwarf:
 	}
 
 	/* Settng up probe points */
-	add_trace_kprobe_events(session.probes, session.nr_probe);
+	add_trace_kprobe_events(session.probes, session.nr_probe,
+				session.force_add);
 	return 0;
 }
 
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 0b769bc..e74ecfc 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -482,7 +482,7 @@ static void write_trace_kprobe_event(int fd, const char *buf)
 }
 
 static void get_new_event_name(char *buf, size_t len, const char *base,
-			       struct strlist *namelist)
+			       struct strlist *namelist, bool allow_suffix)
 {
 	int i, ret;
 
@@ -493,6 +493,12 @@ static void get_new_event_name(char *buf, size_t len, const char *base,
 	if (!strlist__has_entry(namelist, buf))
 		return;
 
+	if (!allow_suffix) {
+		pr_warning("Error: event \"%s\" already exists. "
+			   "(Use -f to force duplicates.)\n", base);
+		die("Can't add new event.");
+	}
+
 	/* Try to add suffix */
 	for (i = 1; i < MAX_EVENT_INDEX; i++) {
 		ret = e_snprintf(buf, len, "%s_%d", base, i);
@@ -505,13 +511,15 @@ static void get_new_event_name(char *buf, size_t len, const char *base,
 		die("Too many events are on the same function.");
 }
 
-void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
+void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
+			     bool force_add)
 {
 	int i, j, fd;
 	struct probe_point *pp;
 	char buf[MAX_CMDLEN];
 	char event[64];
 	struct strlist *namelist;
+	bool allow_suffix;
 
 	fd = open_kprobe_events(O_RDWR, O_APPEND);
 	/* Get current event names */
@@ -524,9 +532,12 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 		if (!pp->group)
 			pp->group = strdup(PERFPROBE_GROUP);
 		DIE_IF(!pp->event || !pp->group);
+		/* If force_add is true, suffix search is allowed */
+		allow_suffix = force_add;
 		for (i = 0; i < pp->found; i++) {
 			/* Get an unused new event name */
-			get_new_event_name(event, 64, pp->event, namelist);
+			get_new_event_name(event, 64, pp->event, namelist,
+					   allow_suffix);
 			snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n",
 				 pp->retprobe ? 'r' : 'p',
 				 pp->group, event,
@@ -538,6 +549,13 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 			show_perf_probe_event(event, buf, pp);
 			/* Add added event name to namelist */
 			strlist__add(namelist, event);
+			/*
+			 * Probes after the first probe which comes from same
+			 * user input are always allowed to add suffix, because
+			 * there might be several addresses corresponding to
+			 * one code line.
+			 */
+			allow_suffix = true;
 		}
 	}
 	/* Show how to use the event. */
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 8bb22f5..8fd3052 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -10,7 +10,8 @@ extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
 extern int synthesize_perf_probe_event(struct probe_point *pp);
 extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
 extern int synthesize_trace_kprobe_event(struct probe_point *pp);
-extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes);
+extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
+				    bool force_add);
 extern void del_trace_kprobe_events(struct strlist *dellist);
 extern void show_perf_probe_events(void);
 


-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com

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

* Re: [PATCH -tip 00/14] perf-probe updates
  2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
                   ` (13 preceding siblings ...)
  2009-12-15 15:28 ` [PATCH -tip 13/14] perf probe: Check symbols in symtab/kallsyms Masami Hiramatsu
@ 2009-12-15 19:23 ` Ingo Molnar
  14 siblings, 0 replies; 30+ messages in thread
From: Ingo Molnar @ 2009-12-15 19:23 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Frederic Weisbecker, lkml, Paul Mackerras,
	Arnaldo Carvalho de Melo, Steven Rostedt, Jim Keniston,
	Ananth N Mavinakayanahalli, Christoph Hellwig, Frank Ch. Eigler,
	Jason Baron, K.Prasad, Peter Zijlstra, Srikar Dronamraju,
	systemtap, DLE


* Masami Hiramatsu <mhiramat@redhat.com> wrote:

> Hi Ingo,
> 
> Here are several bugfixes and updates of perf-probe.
> This updates includes below features.
> 
>   - Support checking kernel Build-ID
> 	Comparing vmlinux build-id and running kernel build-id
> 	can prevent user to set incorrect probes by using
> 	old/incorrect vmlinux.
> 
>   - Symbol search by libelf/kallsyms
> 	This allows to check probed symbol exists in the kernel
> 	even if debuginfo is not available.
> 
>   - Support glob expression with --del option (like --del '*')
> 	This allows users to use wildcard for specifying
> 	deleting events.
> 
>   - Reject adding same-name events
> 	Rejecting to add event which name already exists.
> 
>   - Support event name specifying for new events
> 	This allows users to set their own name to new
> 	events. Currently setting group name is not
> 	allowed, because it will conflict with other
> 	tracepoints and kmem event.
> 
> I think the glob expression (wildcard matching) can be
> applied to other perf tools for choosing events, and it
> will give user better experience :-)

Very nice improvements! :)

Applied, thanks!

	Ingo

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

* [tip:perf/urgent] perf probe: Check the result of e_snprintf()
  2009-12-15 15:26 ` [PATCH -tip 02/14] perf probe: Check the result of e_snprintf() Masami Hiramatsu
@ 2009-12-15 19:26   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  7e990a51264cb0c1400155ba72d56f5158ccf919
Gitweb:     http://git.kernel.org/tip/7e990a51264cb0c1400155ba72d56f5158ccf919
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:31:21 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:00 +0100

perf probe: Check the result of e_snprintf()

Fix show_perf_probe_event() to check the result of e_snprintf().

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153121.17436.34674.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/probe-event.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index add379c..1653a62 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -385,10 +385,12 @@ static void clear_probe_point(struct probe_point *pp)
 static void show_perf_probe_event(const char *group, const char *event,
 				  const char *place, struct probe_point *pp)
 {
-	int i;
+	int i, ret;
 	char buf[128];
 
-	e_snprintf(buf, 128, "%s:%s", group, event);
+	ret = e_snprintf(buf, 128, "%s:%s", group, event);
+	if (ret < 0)
+		die("Failed to copy event: %s", strerror(-ret));
 	printf("  %-40s (on %s", buf, place);
 
 	if (pp->nr_args > 0) {

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

* [tip:perf/urgent] perf probe: Cleanup struct session in builtin-probe.c
  2009-12-15 15:26 ` [PATCH -tip 01/14] perf probe: Cleanup struct session in builtin-probe.c Masami Hiramatsu
@ 2009-12-15 19:27   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  fac13fd54e2bfbb0b49683a9b3ae2bf2a0d7677f
Gitweb:     http://git.kernel.org/tip/fac13fd54e2bfbb0b49683a9b3ae2bf2a0d7677f
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:31:14 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:21:59 +0100

perf probe: Cleanup struct session in builtin-probe.c

Clean up struct session in builtin-probe.c, including
change need_dwarf to bool and move listing flag into
struct session as list_events flag.

This also changes parse_perf_probe_event() interface
due to code readability.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153114.17436.77000.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-probe.c    |   13 +++++++------
 tools/perf/util/probe-event.c |   12 +++++++-----
 tools/perf/util/probe-event.h |    4 +++-
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 5a47c1e..559eeb4 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -59,13 +59,13 @@ const char *default_search_path[NR_SEARCH_PATH] = {
 static struct {
 	char *vmlinux;
 	char *release;
-	int need_dwarf;
+	bool need_dwarf;
+	bool list_events;
 	int nr_probe;
 	struct probe_point probes[MAX_PROBES];
 	struct strlist *dellist;
 } session;
 
-static bool listing;
 
 /* Parse an event definition. Note that any error must die. */
 static void parse_probe_event(const char *str)
@@ -77,7 +77,7 @@ static void parse_probe_event(const char *str)
 		die("Too many probes (> %d) are specified.", MAX_PROBES);
 
 	/* Parse perf-probe event into probe_point */
-	session.need_dwarf = parse_perf_probe_event(str, pp);
+	parse_perf_probe_event(str, pp, &session.need_dwarf);
 
 	pr_debug("%d arguments\n", pp->nr_args);
 }
@@ -166,7 +166,8 @@ static const struct option options[] = {
 	OPT_STRING('k', "vmlinux", &session.vmlinux, "file",
 		"vmlinux/module pathname"),
 #endif
-	OPT_BOOLEAN('l', "list", &listing, "list up current probe events"),
+	OPT_BOOLEAN('l', "list", &session.list_events,
+		    "list up current probe events"),
 	OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.",
 		opt_del_probe_event),
 	OPT_CALLBACK('a', "add", NULL,
@@ -207,10 +208,10 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 	if (argc > 0)
 		parse_probe_event_argv(argc, argv);
 
-	if ((session.nr_probe == 0 && !session.dellist && !listing))
+	if ((!session.nr_probe && !session.dellist && !session.list_events))
 		usage_with_options(probe_usage, options);
 
-	if (listing) {
+	if (session.list_events) {
 		if (session.nr_probe != 0 || session.dellist) {
 			pr_warning("  Error: Don't use --list with"
 				   " --add/--del.\n");
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index d14a458..add379c 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -150,10 +150,13 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
 }
 
 /* Parse perf-probe event definition */
-int parse_perf_probe_event(const char *str, struct probe_point *pp)
+void parse_perf_probe_event(const char *str, struct probe_point *pp,
+			    bool *need_dwarf)
 {
 	char **argv;
-	int argc, i, need_dwarf = 0;
+	int argc, i;
+
+	*need_dwarf = false;
 
 	argv = argv_split(str, &argc);
 	if (!argv)
@@ -164,7 +167,7 @@ int parse_perf_probe_event(const char *str, struct probe_point *pp)
 	/* Parse probe point */
 	parse_perf_probe_probepoint(argv[0], pp);
 	if (pp->file || pp->line)
-		need_dwarf = 1;
+		*need_dwarf = true;
 
 	/* Copy arguments and ensure return probe has no C argument */
 	pp->nr_args = argc - 1;
@@ -177,12 +180,11 @@ int parse_perf_probe_event(const char *str, struct probe_point *pp)
 			if (pp->retprobe)
 				semantic_error("You can't specify local"
 						" variable for kretprobe");
-			need_dwarf = 1;
+			*need_dwarf = true;
 		}
 	}
 
 	argv_free(argv);
-	return need_dwarf;
 }
 
 /* Parse kprobe_events event into struct probe_point */
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index f752159..028575b 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -1,10 +1,12 @@
 #ifndef _PROBE_EVENT_H
 #define _PROBE_EVENT_H
 
+#include <stdbool.h>
 #include "probe-finder.h"
 #include "strlist.h"
 
-extern int parse_perf_probe_event(const char *str, struct probe_point *pp);
+extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
+				   bool *need_dwarf);
 extern int synthesize_perf_probe_event(struct probe_point *pp);
 extern void parse_trace_kprobe_event(const char *str, char **group,
 				     char **event, struct probe_point *pp);

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

* [tip:perf/urgent] perf probe: Show need-dwarf message only if it is really needed
  2009-12-15 15:27 ` [PATCH -tip 04/14] perf probe: Show need-dwarf message only if it is really needed Masami Hiramatsu
@ 2009-12-15 19:27   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  411edfe5c1ef02a62ec3be56d3e234dbed71ba20
Gitweb:     http://git.kernel.org/tip/411edfe5c1ef02a62ec3be56d3e234dbed71ba20
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:31:35 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:01 +0100

perf probe: Show need-dwarf message only if it is really needed

Show need-dwarf message only if the probe is really requires
debuginfo analysis. This also use pr_debug for debugging message
instead of pr_warning.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153135.17436.99052.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-probe.c     |   18 +++++++++++-------
 tools/perf/util/probe-finder.c |    4 +---
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 919037b..438a7bb 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -261,15 +261,19 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 
 		lseek(fd, SEEK_SET, 0);
 		ret = find_probepoint(fd, pp);
-		if (ret < 0) {
-			if (session.need_dwarf)
-				die("Could not analyze debuginfo.");
-
-			pr_warning("An error occurred in debuginfo analysis. Try to use symbols.\n");
-			break;
-		}
+		if (ret > 0)
+			continue;
 		if (ret == 0)	/* No error but failed to find probe point. */
 			die("No probe point found.");
+		/* Error path */
+		if (session.need_dwarf) {
+			if (ret == -ENOENT)
+				pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n");
+			die("Could not analyze debuginfo.");
+		}
+		pr_debug("An error occurred in debuginfo analysis."
+			 " Try to use symbols.\n");
+		break;
 	}
 	close(fd);
 
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 4585f1d..4b852c0 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -687,10 +687,8 @@ int find_probepoint(int fd, struct probe_point *pp)
 	struct probe_finder pf = {.pp = pp};
 
 	ret = dwarf_init(fd, DW_DLC_READ, 0, 0, &__dw_debug, &__dw_error);
-	if (ret != DW_DLV_OK) {
-		pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO.\n");
+	if (ret != DW_DLV_OK)
 		return -ENOENT;
-	}
 
 	pp->found = 0;
 	while (++cu_number) {

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

* [tip:perf/urgent] perf probe: Fix to show which probe point is not found
  2009-12-15 15:28 ` [PATCH -tip 14/14] perf probe: Fix to show which probe point is not found Masami Hiramatsu
@ 2009-12-15 19:28   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  7ef17aafc98406d01ebbf7fe98ef1332b70d20bb
Gitweb:     http://git.kernel.org/tip/7ef17aafc98406d01ebbf7fe98ef1332b70d20bb
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:32:47 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:05 +0100

perf probe: Fix to show which probe point is not found

Fix perf probe to show which probe point is not found.
With out this patch, it shows just "No probe point found."
This doesn't help users if they specify several probes.
e.g.

 # perf probe -f --add schedule --add test
  Fatal: No probe point found.

This patch makes error message more helpful as below.

 # perf probe --add schedule --add test
  Fatal: Probe point 'test' not found. - probe not added.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153247.17436.49068.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-probe.c    |    7 +++++--
 tools/perf/util/probe-event.c |   34 ++++++++++++++++++++++++----------
 tools/perf/util/probe-event.h |    1 +
 3 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 6b0e4cf..520b064 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -265,8 +265,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 		ret = find_probepoint(fd, pp);
 		if (ret > 0)
 			continue;
-		if (ret == 0)	/* No error but failed to find probe point. */
-			die("No probe point found.");
+		if (ret == 0) {	/* No error but failed to find probe point. */
+			synthesize_perf_probe_point(pp);
+			die("Probe point '%s' not found. - probe not added.",
+			    pp->probes[0]);
+		}
 		/* Error path */
 		if (session.need_dwarf) {
 			if (ret == -ENOENT)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index b05d532..2ca6215 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -249,11 +249,12 @@ void parse_trace_kprobe_event(const char *str, struct probe_point *pp)
 	argv_free(argv);
 }
 
-int synthesize_perf_probe_event(struct probe_point *pp)
+/* Synthesize only probe point (not argument) */
+int synthesize_perf_probe_point(struct probe_point *pp)
 {
 	char *buf;
 	char offs[64] = "", line[64] = "";
-	int i, len, ret;
+	int ret;
 
 	pp->probes[0] = buf = zalloc(MAX_CMDLEN);
 	if (!buf)
@@ -274,10 +275,24 @@ int synthesize_perf_probe_event(struct probe_point *pp)
 				 offs, pp->retprobe ? "%return" : "", line);
 	else
 		ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", pp->file, line);
-	if (ret <= 0)
-		goto error;
-	len = ret;
+	if (ret <= 0) {
+error:
+		free(pp->probes[0]);
+		pp->probes[0] = NULL;
+	}
+	return ret;
+}
+
+int synthesize_perf_probe_event(struct probe_point *pp)
+{
+	char *buf;
+	int i, len, ret;
 
+	len = synthesize_perf_probe_point(pp);
+	if (len < 0)
+		return 0;
+
+	buf = pp->probes[0];
 	for (i = 0; i < pp->nr_args; i++) {
 		ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
 				 pp->args[i]);
@@ -290,6 +305,7 @@ int synthesize_perf_probe_event(struct probe_point *pp)
 	return pp->found;
 error:
 	free(pp->probes[0]);
+	pp->probes[0] = NULL;
 
 	return ret;
 }
@@ -319,6 +335,7 @@ int synthesize_trace_kprobe_event(struct probe_point *pp)
 	return pp->found;
 error:
 	free(pp->probes[0]);
+	pp->probes[0] = NULL;
 
 	return ret;
 }
@@ -418,7 +435,7 @@ static void show_perf_probe_event(const char *event, const char *place,
 /* List up current perf-probe events */
 void show_perf_probe_events(void)
 {
-	int fd, nr;
+	int fd;
 	struct probe_point pp;
 	struct strlist *rawlist;
 	struct str_node *ent;
@@ -430,10 +447,7 @@ void show_perf_probe_events(void)
 	strlist__for_each(ent, rawlist) {
 		parse_trace_kprobe_event(ent->s, &pp);
 		/* Synthesize only event probe point */
-		nr = pp.nr_args;
-		pp.nr_args = 0;
-		synthesize_perf_probe_event(&pp);
-		pp.nr_args = nr;
+		synthesize_perf_probe_point(&pp);
 		/* Show an event */
 		show_perf_probe_event(pp.event, pp.probes[0], &pp);
 		clear_probe_point(&pp);
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 8fd3052..7f1d499 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -7,6 +7,7 @@
 
 extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
 				   bool *need_dwarf);
+extern int synthesize_perf_probe_point(struct probe_point *pp);
 extern int synthesize_perf_probe_event(struct probe_point *pp);
 extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
 extern int synthesize_trace_kprobe_event(struct probe_point *pp);

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

* [tip:perf/urgent] perf probe: Add glob matching support on --del
  2009-12-15 15:27 ` [PATCH -tip 09/14] perf probe: Add glob matching support on --del Masami Hiramatsu
@ 2009-12-15 19:28   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  bbbb521bc61008b280c72ad6e29a8a7558d3acfa
Gitweb:     http://git.kernel.org/tip/bbbb521bc61008b280c72ad6e29a8a7558d3acfa
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:32:10 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:03 +0100

perf probe: Add glob matching support on --del

Add glob-expression matching support on --del option.
You can use wildcards for specifying deleting events.
e.g.

 Clear all probe events:

 # perf probe --del '*'

 Clear probes on schedule():

 # perf probe --del 'schedule*'

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153210.17436.12327.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/probe-event.c |   52 ++++++++++++++++++++++++++++++----------
 tools/perf/util/string.c      |   25 +++++++++++++++++++
 tools/perf/util/string.h      |    2 +
 3 files changed, 66 insertions(+), 13 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 3e30be9..5e99e52 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -532,26 +532,50 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 	close(fd);
 }
 
+static void __del_trace_kprobe_event(int fd, struct str_node *ent)
+{
+	char *p;
+	char buf[128];
+
+	/* Convert from perf-probe event to trace-kprobe event */
+	if (e_snprintf(buf, 128, "-:%s", ent->s) < 0)
+		die("Failed to copy event.");
+	p = strchr(buf + 2, ':');
+	if (!p)
+		die("Internal error: %s should have ':' but not.", ent->s);
+	*p = '/';
+
+	write_trace_kprobe_event(fd, buf);
+	printf("Remove event: %s\n", ent->s);
+}
+
 static void del_trace_kprobe_event(int fd, const char *group,
 				   const char *event, struct strlist *namelist)
 {
 	char buf[128];
-	struct str_node *ent;
+	struct str_node *ent, *n;
+	int found = 0;
 
 	if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
 		die("Failed to copy event.");
-	ent = strlist__find(namelist, buf);
-	if (!ent) {
-		pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf);
-		return;
-	}
-	/* Convert from perf-probe event to trace-kprobe event */
-	if (e_snprintf(buf, 128, "-:%s/%s", group, event) < 0)
-		die("Failed to copy event.");
 
-	write_trace_kprobe_event(fd, buf);
-	printf("Remove event: %s:%s\n", group, event);
-	strlist__remove(namelist, ent);
+	if (strpbrk(buf, "*?")) { /* Glob-exp */
+		strlist__for_each_safe(ent, n, namelist)
+			if (strglobmatch(ent->s, buf)) {
+				found++;
+				__del_trace_kprobe_event(fd, ent);
+				strlist__remove(namelist, ent);
+			}
+	} else {
+		ent = strlist__find(namelist, buf);
+		if (ent) {
+			found++;
+			__del_trace_kprobe_event(fd, ent);
+			strlist__remove(namelist, ent);
+		}
+	}
+	if (found == 0)
+		pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf);
 }
 
 void del_trace_kprobe_events(struct strlist *dellist)
@@ -570,15 +594,17 @@ void del_trace_kprobe_events(struct strlist *dellist)
 		str = strdup(ent->s);
 		if (!str)
 			die("Failed to copy event.");
+		pr_debug("Parsing: %s\n", str);
 		p = strchr(str, ':');
 		if (p) {
 			group = str;
 			*p = '\0';
 			event = p + 1;
 		} else {
-			group = PERFPROBE_GROUP;
+			group = "*";
 			event = str;
 		}
+		pr_debug("Group: %s, Event: %s\n", group, event);
 		del_trace_kprobe_event(fd, group, event, namelist);
 		free(str);
 	}
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index f24a8cc..5352d7d 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -226,3 +226,28 @@ fail:
 	argv_free(argv);
 	return NULL;
 }
+
+/* Glob expression pattern matching */
+bool strglobmatch(const char *str, const char *pat)
+{
+	while (*str && *pat && *pat != '*') {
+		if (*pat == '?') {
+			str++;
+			pat++;
+		} else
+			if (*str++ != *pat++)
+				return false;
+	}
+	/* Check wild card */
+	if (*pat == '*') {
+		while (*pat == '*')
+			pat++;
+		if (!*pat)	/* Tail wild card matches all */
+			return true;
+		while (*str)
+			if (strglobmatch(str++, pat))
+				return true;
+	}
+	return !*str && !*pat;
+}
+
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h
index bfecec2..02ede58 100644
--- a/tools/perf/util/string.h
+++ b/tools/perf/util/string.h
@@ -1,6 +1,7 @@
 #ifndef __PERF_STRING_H_
 #define __PERF_STRING_H_
 
+#include <stdbool.h>
 #include "types.h"
 
 int hex2u64(const char *ptr, u64 *val);
@@ -8,6 +9,7 @@ char *strxfrchar(char *s, char from, char to);
 s64 perf_atoll(const char *str);
 char **argv_split(const char *str, int *argcp);
 void argv_free(char **argv);
+bool strglobmatch(const char *str, const char *pat);
 
 #define _STR(x) #x
 #define STR(x) _STR(x)

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

* [tip:perf/urgent] perf probe: Check symbols in symtab/kallsyms
  2009-12-15 15:28 ` [PATCH -tip 13/14] perf probe: Check symbols in symtab/kallsyms Masami Hiramatsu
@ 2009-12-15 19:28   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  62bdc1b38e2abf3f500229c3bf4c82d33575d1ae
Gitweb:     http://git.kernel.org/tip/62bdc1b38e2abf3f500229c3bf4c82d33575d1ae
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:32:40 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:05 +0100

perf probe: Check symbols in symtab/kallsyms

Check symbols in symtab/kallsyms when no debuginfo
is available.

e.g.

 # perf probe test
  Fatal: Kernel symbol 'test' not found - probe not added.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153239.17436.55034.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-probe.c |   32 ++++++++++++++++++++++----------
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 0584b7a..6b0e4cf 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -59,6 +59,7 @@ static struct {
 	struct strlist *dellist;
 	struct symbol_conf conf;
 	struct perf_session *psession;
+	struct map *kmap;
 } session;
 
 
@@ -115,22 +116,26 @@ static int opt_del_probe_event(const struct option *opt __used,
 	return 0;
 }
 
+/* Currently just checking function name from symbol map */
+static void evaluate_probe_point(struct probe_point *pp)
+{
+	struct symbol *sym;
+	sym = map__find_symbol_by_name(session.kmap, pp->function,
+				       session.psession, NULL);
+	if (!sym)
+		die("Kernel symbol \'%s\' not found - probe not added.",
+		    pp->function);
+}
+
 #ifndef NO_LIBDWARF
 static int open_vmlinux(void)
 {
-	struct map *kmap;
-	kmap = map_groups__find_by_name(&session.psession->kmaps,
-					MAP__FUNCTION, "[kernel.kallsyms]");
-	if (!kmap) {
-		pr_debug("Could not find kernel map.\n");
-		return -ENOENT;
-	}
-	if (map__load(kmap, session.psession, NULL) < 0) {
+	if (map__load(session.kmap, session.psession, NULL) < 0) {
 		pr_debug("Failed to load kernel map.\n");
 		return -EINVAL;
 	}
-	pr_debug("Try to open %s\n", kmap->dso->long_name);
-	return open(kmap->dso->long_name, O_RDONLY);
+	pr_debug("Try to open %s\n", session.kmap->dso->long_name);
+	return open(session.kmap->dso->long_name, O_RDONLY);
 }
 #endif
 
@@ -219,6 +224,7 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 	}
 
 	/* Initialize symbol maps for vmlinux */
+	session.conf.sort_by_name = true;
 	if (session.conf.vmlinux_name == NULL)
 		session.conf.try_vmlinux_path = true;
 	if (symbol__init(&session.conf) < 0)
@@ -227,6 +233,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 					     &session.conf);
 	if (session.psession == NULL)
 		die("Failed to init perf_session.");
+	session.kmap = map_groups__find_by_name(&session.psession->kmaps,
+						MAP__FUNCTION,
+						"[kernel.kallsyms]");
+	if (!session.kmap)
+		die("Could not find kernel map.\n");
 
 	if (session.need_dwarf)
 #ifdef NO_LIBDWARF
@@ -277,6 +288,7 @@ end_dwarf:
 		if (pp->found)	/* This probe is already found. */
 			continue;
 
+		evaluate_probe_point(pp);
 		ret = synthesize_trace_kprobe_event(pp);
 		if (ret == -E2BIG)
 			die("probe point definition becomes too long.");

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

* [tip:perf/urgent] perf probe: Use strlist__for_each macros in probe-event.c
  2009-12-15 15:27 ` [PATCH -tip 08/14] perf probe: Use strlist__for_each macros in probe-event.c Masami Hiramatsu
@ 2009-12-15 19:28   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  adf365f486280e4577c9eabd7d8e118e5994a03e
Gitweb:     http://git.kernel.org/tip/adf365f486280e4577c9eabd7d8e118e5994a03e
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:32:03 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:02 +0100

perf probe: Use strlist__for_each macros in probe-event.c

Use strlist__for_each macros instead of using strlist__entry()
and index variable.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153203.17436.52039.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/probe-event.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index eab25d6..3e30be9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -404,7 +404,6 @@ static void show_perf_probe_event(const char *group, const char *event,
 /* List up current perf-probe events */
 void show_perf_probe_events(void)
 {
-	unsigned int i;
 	int fd, nr;
 	char *group, *event;
 	struct probe_point pp;
@@ -415,8 +414,7 @@ void show_perf_probe_events(void)
 	rawlist = get_trace_kprobe_event_rawlist(fd);
 	close(fd);
 
-	for (i = 0; i < strlist__nr_entries(rawlist); i++) {
-		ent = strlist__entry(rawlist, i);
+	strlist__for_each(ent, rawlist) {
 		parse_trace_kprobe_event(ent->s, &group, &event, &pp);
 		/* Synthesize only event probe point */
 		nr = pp.nr_args;
@@ -436,7 +434,6 @@ void show_perf_probe_events(void)
 /* Get current perf-probe event names */
 static struct strlist *get_perf_event_names(int fd, bool include_group)
 {
-	unsigned int i;
 	char *group, *event;
 	char buf[128];
 	struct strlist *sl, *rawlist;
@@ -445,8 +442,7 @@ static struct strlist *get_perf_event_names(int fd, bool include_group)
 	rawlist = get_trace_kprobe_event_rawlist(fd);
 
 	sl = strlist__new(true, NULL);
-	for (i = 0; i < strlist__nr_entries(rawlist); i++) {
-		ent = strlist__entry(rawlist, i);
+	strlist__for_each(ent, rawlist) {
 		parse_trace_kprobe_event(ent->s, &group, &event, NULL);
 		if (include_group) {
 			if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
@@ -561,7 +557,6 @@ static void del_trace_kprobe_event(int fd, const char *group,
 void del_trace_kprobe_events(struct strlist *dellist)
 {
 	int fd;
-	unsigned int i;
 	const char *group, *event;
 	char *p, *str;
 	struct str_node *ent;
@@ -571,8 +566,7 @@ void del_trace_kprobe_events(struct strlist *dellist)
 	/* Get current event names */
 	namelist = get_perf_event_names(fd, true);
 
-	for (i = 0; i < strlist__nr_entries(dellist); i++) {
-		ent = strlist__entry(dellist, i);
+	strlist__for_each(ent, dellist) {
 		str = strdup(ent->s);
 		if (!str)
 			die("Failed to copy event.");

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

* [tip:perf/urgent] perf tools: Add for_each macros for strlist
  2009-12-15 15:27 ` [PATCH -tip 07/14] perf tools: Add for_each macros for strlist Masami Hiramatsu
@ 2009-12-15 19:28   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  abf5ef72477f9fb559a8a034fd6e6c397bb37e1f
Gitweb:     http://git.kernel.org/tip/abf5ef72477f9fb559a8a034fd6e6c397bb37e1f
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:31:56 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:02 +0100

perf tools: Add for_each macros for strlist

Add for_each iteration macros for strlist. This patch
introduces strlist__for_each() and strlist__for_each_safe(),
both are similar to list_for_each() and list_for_each_safe().

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153156.17436.49157.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/strlist.h |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
index 59091c7..3ba8390 100644
--- a/tools/perf/util/strlist.h
+++ b/tools/perf/util/strlist.h
@@ -40,5 +40,39 @@ static inline unsigned int strlist__nr_entries(const struct strlist *self)
 	return self->nr_entries;
 }
 
+/* For strlist iteration */
+static inline struct str_node *strlist__first(struct strlist *self)
+{
+	struct rb_node *rn = rb_first(&self->entries);
+	return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
+}
+static inline struct str_node *strlist__next(struct str_node *sn)
+{
+	struct rb_node *rn;
+	if (!sn)
+		return NULL;
+	rn = rb_next(&sn->rb_node);
+	return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
+}
+
+/**
+ * strlist_for_each      - iterate over a strlist
+ * @pos:	the &struct str_node to use as a loop cursor.
+ * @self:	the &struct strlist for loop.
+ */
+#define strlist__for_each(pos, self)	\
+	for (pos = strlist__first(self); pos; pos = strlist__next(pos))
+
+/**
+ * strlist_for_each_safe - iterate over a strlist safe against removal of
+ *                         str_node
+ * @pos:	the &struct str_node to use as a loop cursor.
+ * @n:		another &struct str_node to use as temporary storage.
+ * @self:	the &struct strlist for loop.
+ */
+#define strlist__for_each_safe(pos, n, self)	\
+	for (pos = strlist__first(self), n = strlist__next(pos); pos;\
+	     pos = n, n = strlist__next(n))
+
 int strlist__parse_list(struct strlist *self, const char *s);
 #endif /* __PERF_STRLIST_H */

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

* [tip:perf/urgent] perf probe: Fix --del to update current event list
  2009-12-15 15:27 ` [PATCH -tip 06/14] perf probe: Fix --del to update current event list Masami Hiramatsu
@ 2009-12-15 19:29   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  3e3405906dab00afecd5a16871850a088eba4626
Gitweb:     http://git.kernel.org/tip/3e3405906dab00afecd5a16871850a088eba4626
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:31:49 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:01 +0100

perf probe: Fix --del to update current event list

Fix --del option to update current existing event list
after perf probe deleted an event.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153149.17436.61265.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/probe-event.c |    5 ++++-
 tools/perf/util/strlist.c     |    6 +++---
 tools/perf/util/strlist.h     |    7 ++++++-
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 1eacee6..eab25d6 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -540,10 +540,12 @@ static void del_trace_kprobe_event(int fd, const char *group,
 				   const char *event, struct strlist *namelist)
 {
 	char buf[128];
+	struct str_node *ent;
 
 	if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
 		die("Failed to copy event.");
-	if (!strlist__has_entry(namelist, buf)) {
+	ent = strlist__find(namelist, buf);
+	if (!ent) {
 		pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf);
 		return;
 	}
@@ -553,6 +555,7 @@ static void del_trace_kprobe_event(int fd, const char *group,
 
 	write_trace_kprobe_event(fd, buf);
 	printf("Remove event: %s:%s\n", group, event);
+	strlist__remove(namelist, ent);
 }
 
 void del_trace_kprobe_events(struct strlist *dellist)
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
index 7ad3817..6783a20 100644
--- a/tools/perf/util/strlist.c
+++ b/tools/perf/util/strlist.c
@@ -102,7 +102,7 @@ void strlist__remove(struct strlist *self, struct str_node *sn)
 	str_node__delete(sn, self->dupstr);
 }
 
-bool strlist__has_entry(struct strlist *self, const char *entry)
+struct str_node *strlist__find(struct strlist *self, const char *entry)
 {
 	struct rb_node **p = &self->entries.rb_node;
 	struct rb_node *parent = NULL;
@@ -120,10 +120,10 @@ bool strlist__has_entry(struct strlist *self, const char *entry)
 		else if (rc < 0)
 			p = &(*p)->rb_right;
 		else
-			return true;
+			return sn;
 	}
 
-	return false;
+	return NULL;
 }
 
 static int strlist__parse_list_entry(struct strlist *self, const char *s)
diff --git a/tools/perf/util/strlist.h b/tools/perf/util/strlist.h
index cb46593..59091c7 100644
--- a/tools/perf/util/strlist.h
+++ b/tools/perf/util/strlist.h
@@ -23,7 +23,12 @@ int strlist__load(struct strlist *self, const char *filename);
 int strlist__add(struct strlist *self, const char *str);
 
 struct str_node *strlist__entry(const struct strlist *self, unsigned int idx);
-bool strlist__has_entry(struct strlist *self, const char *entry);
+struct str_node *strlist__find(struct strlist *self, const char *entry);
+
+static inline bool strlist__has_entry(struct strlist *self, const char *entry)
+{
+	return strlist__find(self, entry) != NULL;
+}
 
 static inline bool strlist__empty(const struct strlist *self)
 {

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

* [tip:perf/urgent] perf probe: Check hyphen only argument
  2009-12-15 15:27 ` [PATCH -tip 03/14] perf probe: Check hyphen only argument Masami Hiramatsu
@ 2009-12-15 19:29   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  ce11a603ae40e0ad32aeb378cff81e3fdaec390d
Gitweb:     http://git.kernel.org/tip/ce11a603ae40e0ad32aeb378cff81e3fdaec390d
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:31:28 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:00 +0100

perf probe: Check hyphen only argument

Check hyphen only command argument, because perf-probe doesn't
support event recording feature yet.

e.g.

 # perf probe -
  Error: '-' is not supported.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153128.17436.9266.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-probe.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 559eeb4..919037b 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -205,8 +205,13 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 
 	argc = parse_options(argc, argv, options, probe_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
-	if (argc > 0)
+	if (argc > 0) {
+		if (strcmp(argv[0], "-") == 0) {
+			pr_warning("  Error: '-' is not supported.\n");
+			usage_with_options(probe_usage, options);
+		}
 		parse_probe_event_argv(argc, argv);
+	}
 
 	if ((!session.nr_probe && !session.dellist && !session.list_events))
 		usage_with_options(probe_usage, options);

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

* [tip:perf/urgent] perf probe: Fix --del to show info instead of warning
  2009-12-15 15:27 ` [PATCH -tip 05/14] perf probe: Fix --del to show info instead of warning Masami Hiramatsu
@ 2009-12-15 19:29   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  f6bbff77252cf12c82d480eaf6d9189129d1040a
Gitweb:     http://git.kernel.org/tip/f6bbff77252cf12c82d480eaf6d9189129d1040a
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:31:42 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:01 +0100

perf probe: Fix --del to show info instead of warning

Fix --del option to show info message instead of warning
if failing to find specified event.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153142.17436.7793.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/util/probe-event.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 1653a62..1eacee6 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -544,7 +544,7 @@ static void del_trace_kprobe_event(int fd, const char *group,
 	if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
 		die("Failed to copy event.");
 	if (!strlist__has_entry(namelist, buf)) {
-		pr_warning("Warning: event \"%s\" is not found.\n", buf);
+		pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf);
 		return;
 	}
 	/* Convert from perf-probe event to trace-kprobe event */

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

* [tip:perf/urgent] perf probe: Check build-id of vmlinux
  2009-12-15 15:28 ` [PATCH -tip 12/14] perf probe: Check build-id of vmlinux Masami Hiramatsu
@ 2009-12-15 19:29   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  a128168d1e79e537d6666655e7771d973e9230e3
Gitweb:     http://git.kernel.org/tip/a128168d1e79e537d6666655e7771d973e9230e3
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:32:33 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:04 +0100

perf probe: Check build-id of vmlinux

Check build-id of vmlinux by using functions in symbol.c.
This also exposes map__load() for getting vmlinux path,
and removes vmlinux path list in builtin-probe.c,
because symbol.c already has that. Checking build-id
prevents users to open old or different debuginfo from
current running kernel.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153232.17436.45539.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-probe.c |   72 ++++++++++++++++++-------------------------
 tools/perf/util/event.h    |    2 +
 tools/perf/util/map.c      |   14 +++++---
 3 files changed, 41 insertions(+), 47 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 8b4fdae..0584b7a 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -38,33 +38,27 @@
 #include "util/strlist.h"
 #include "util/event.h"
 #include "util/debug.h"
+#include "util/symbol.h"
+#include "util/thread.h"
+#include "util/session.h"
 #include "util/parse-options.h"
 #include "util/parse-events.h"	/* For debugfs_path */
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
 
-/* Default vmlinux search paths */
-#define NR_SEARCH_PATH 4
-const char *default_search_path[NR_SEARCH_PATH] = {
-"/lib/modules/%s/build/vmlinux",		/* Custom build kernel */
-"/usr/lib/debug/lib/modules/%s/vmlinux",	/* Red Hat debuginfo */
-"/boot/vmlinux-debug-%s",			/* Ubuntu */
-"./vmlinux",					/* CWD */
-};
-
 #define MAX_PATH_LEN 256
 #define MAX_PROBES 128
 
 /* Session management structure */
 static struct {
-	char *vmlinux;
-	char *release;
 	bool need_dwarf;
 	bool list_events;
 	bool force_add;
 	int nr_probe;
 	struct probe_point probes[MAX_PROBES];
 	struct strlist *dellist;
+	struct symbol_conf conf;
+	struct perf_session *psession;
 } session;
 
 
@@ -122,33 +116,21 @@ static int opt_del_probe_event(const struct option *opt __used,
 }
 
 #ifndef NO_LIBDWARF
-static int open_default_vmlinux(void)
+static int open_vmlinux(void)
 {
-	struct utsname uts;
-	char fname[MAX_PATH_LEN];
-	int fd, ret, i;
-
-	ret = uname(&uts);
-	if (ret) {
-		pr_debug("uname() failed.\n");
-		return -errno;
+	struct map *kmap;
+	kmap = map_groups__find_by_name(&session.psession->kmaps,
+					MAP__FUNCTION, "[kernel.kallsyms]");
+	if (!kmap) {
+		pr_debug("Could not find kernel map.\n");
+		return -ENOENT;
 	}
-	session.release = uts.release;
-	for (i = 0; i < NR_SEARCH_PATH; i++) {
-		ret = snprintf(fname, MAX_PATH_LEN,
-			       default_search_path[i], session.release);
-		if (ret >= MAX_PATH_LEN || ret < 0) {
-			pr_debug("Filename(%d,%s) is too long.\n", i,
-				uts.release);
-			errno = E2BIG;
-			return -E2BIG;
-		}
-		pr_debug("try to open %s\n", fname);
-		fd = open(fname, O_RDONLY);
-		if (fd >= 0)
-			break;
+	if (map__load(kmap, session.psession, NULL) < 0) {
+		pr_debug("Failed to load kernel map.\n");
+		return -EINVAL;
 	}
-	return fd;
+	pr_debug("Try to open %s\n", kmap->dso->long_name);
+	return open(kmap->dso->long_name, O_RDONLY);
 }
 #endif
 
@@ -164,8 +146,8 @@ static const struct option options[] = {
 	OPT_BOOLEAN('v', "verbose", &verbose,
 		    "be more verbose (show parsed arguments, etc)"),
 #ifndef NO_LIBDWARF
-	OPT_STRING('k', "vmlinux", &session.vmlinux, "file",
-		"vmlinux/module pathname"),
+	OPT_STRING('k', "vmlinux", &session.conf.vmlinux_name,
+		   "file", "vmlinux pathname"),
 #endif
 	OPT_BOOLEAN('l', "list", &session.list_events,
 		    "list up current probe events"),
@@ -236,17 +218,23 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
 			return 0;
 	}
 
+	/* Initialize symbol maps for vmlinux */
+	if (session.conf.vmlinux_name == NULL)
+		session.conf.try_vmlinux_path = true;
+	if (symbol__init(&session.conf) < 0)
+		die("Failed to init symbol map.");
+	session.psession = perf_session__new(NULL, O_WRONLY, false,
+					     &session.conf);
+	if (session.psession == NULL)
+		die("Failed to init perf_session.");
+
 	if (session.need_dwarf)
 #ifdef NO_LIBDWARF
 		die("Debuginfo-analysis is not supported");
 #else	/* !NO_LIBDWARF */
 		pr_debug("Some probes require debuginfo.\n");
 
-	if (session.vmlinux) {
-		pr_debug("Try to open %s.", session.vmlinux);
-		fd = open(session.vmlinux, O_RDONLY);
-	} else
-		fd = open_default_vmlinux();
+	fd = open_vmlinux();
 	if (fd < 0) {
 		if (session.need_dwarf)
 			die("Could not open debuginfo file.");
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index a92e0b0..8027309 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -152,6 +152,8 @@ size_t map__fprintf(struct map *self, FILE *fp);
 
 struct perf_session;
 
+int map__load(struct map *self, struct perf_session *session,
+	      symbol_filter_t filter);
 struct symbol *map__find_symbol(struct map *self, struct perf_session *session,
 				u64 addr, symbol_filter_t filter);
 struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 8b3dd46..c4d55a0 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -104,12 +104,16 @@ void map__fixup_end(struct map *self)
 
 #define DSO__DELETED "(deleted)"
 
-static int map__load(struct map *self, struct perf_session *session,
-		     symbol_filter_t filter)
+int map__load(struct map *self, struct perf_session *session,
+	      symbol_filter_t filter)
 {
 	const char *name = self->dso->long_name;
-	int nr = dso__load(self->dso, self, session, filter);
+	int nr;
 
+	if (dso__loaded(self->dso, self->type))
+		return 0;
+
+	nr = dso__load(self->dso, self, session, filter);
 	if (nr < 0) {
 		if (self->dso->has_build_id) {
 			char sbuild_id[BUILD_ID_SIZE * 2 + 1];
@@ -147,7 +151,7 @@ static int map__load(struct map *self, struct perf_session *session,
 struct symbol *map__find_symbol(struct map *self, struct perf_session *session,
 				u64 addr, symbol_filter_t filter)
 {
-	if (!dso__loaded(self->dso, self->type) && map__load(self, session, filter) < 0)
+	if (map__load(self, session, filter) < 0)
 		return NULL;
 
 	return dso__find_symbol(self->dso, self->type, addr);
@@ -157,7 +161,7 @@ struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
 					struct perf_session *session,
 					symbol_filter_t filter)
 {
-	if (!dso__loaded(self->dso, self->type) && map__load(self, session, filter) < 0)
+	if (map__load(self, session, filter) < 0)
 		return NULL;
 
 	if (!dso__sorted_by_name(self->dso, self->type))

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

* [tip:perf/urgent] perf probe: Reject second attempt of adding same-name event
  2009-12-15 15:28 ` [PATCH -tip 11/14] perf probe: Reject second attempt of adding same-name event Masami Hiramatsu
@ 2009-12-15 19:29   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  d761b08bff0a9b653f6bd248cea50322e7eccb14
Gitweb:     http://git.kernel.org/tip/d761b08bff0a9b653f6bd248cea50322e7eccb14
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:32:25 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:04 +0100

perf probe: Reject second attempt of adding same-name event

Reject second attempt of adding same-name event. This patch
also provides --force option which allows user to add additional
probe events on the same-name event.

e.g.
(the first attempt : success)
 ./perf probe schedule
 Added new event:
   probe:schedule                           (on schedule+0)

(the second attempt : failure)
 ./perf probe schedule:11
 Error: event "schedule" already exists. (Use -f to force duplicates.)
   Fatal: Can't add new event.

(the second attempt with -f : successfully added)
 ./perf probe -f schedule:11
 Added new event:
   probe:schedule_1                         (on schedule+45)

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153225.17436.15166.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/builtin-probe.c    |    6 +++++-
 tools/perf/util/probe-event.c |   24 +++++++++++++++++++++---
 tools/perf/util/probe-event.h |    3 ++-
 3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index adc0a55..8b4fdae 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -61,6 +61,7 @@ static struct {
 	char *release;
 	bool need_dwarf;
 	bool list_events;
+	bool force_add;
 	int nr_probe;
 	struct probe_point probes[MAX_PROBES];
 	struct strlist *dellist;
@@ -192,6 +193,8 @@ static const struct option options[] = {
 #endif
 		"\t\t\tkprobe-tracer argument format.)\n",
 		opt_add_probe_event),
+	OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events"
+		    " with existing name"),
 	OPT_END()
 };
 
@@ -294,7 +297,8 @@ end_dwarf:
 	}
 
 	/* Settng up probe points */
-	add_trace_kprobe_events(session.probes, session.nr_probe);
+	add_trace_kprobe_events(session.probes, session.nr_probe,
+				session.force_add);
 	return 0;
 }
 
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 3b4cf45..b05d532 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -482,7 +482,7 @@ static void write_trace_kprobe_event(int fd, const char *buf)
 }
 
 static void get_new_event_name(char *buf, size_t len, const char *base,
-			       struct strlist *namelist)
+			       struct strlist *namelist, bool allow_suffix)
 {
 	int i, ret;
 
@@ -493,6 +493,12 @@ static void get_new_event_name(char *buf, size_t len, const char *base,
 	if (!strlist__has_entry(namelist, buf))
 		return;
 
+	if (!allow_suffix) {
+		pr_warning("Error: event \"%s\" already exists. "
+			   "(Use -f to force duplicates.)\n", base);
+		die("Can't add new event.");
+	}
+
 	/* Try to add suffix */
 	for (i = 1; i < MAX_EVENT_INDEX; i++) {
 		ret = e_snprintf(buf, len, "%s_%d", base, i);
@@ -505,13 +511,15 @@ static void get_new_event_name(char *buf, size_t len, const char *base,
 		die("Too many events are on the same function.");
 }
 
-void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
+void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
+			     bool force_add)
 {
 	int i, j, fd;
 	struct probe_point *pp;
 	char buf[MAX_CMDLEN];
 	char event[64];
 	struct strlist *namelist;
+	bool allow_suffix;
 
 	fd = open_kprobe_events(O_RDWR, O_APPEND);
 	/* Get current event names */
@@ -524,9 +532,12 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 		if (!pp->group)
 			pp->group = strdup(PERFPROBE_GROUP);
 		DIE_IF(!pp->event || !pp->group);
+		/* If force_add is true, suffix search is allowed */
+		allow_suffix = force_add;
 		for (i = 0; i < pp->found; i++) {
 			/* Get an unused new event name */
-			get_new_event_name(event, 64, pp->event, namelist);
+			get_new_event_name(event, 64, pp->event, namelist,
+					   allow_suffix);
 			snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n",
 				 pp->retprobe ? 'r' : 'p',
 				 pp->group, event,
@@ -538,6 +549,13 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 			show_perf_probe_event(event, buf, pp);
 			/* Add added event name to namelist */
 			strlist__add(namelist, event);
+			/*
+			 * Probes after the first probe which comes from same
+			 * user input are always allowed to add suffix, because
+			 * there might be several addresses corresponding to
+			 * one code line.
+			 */
+			allow_suffix = true;
 		}
 	}
 	/* Show how to use the event. */
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 8bb22f5..8fd3052 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -10,7 +10,8 @@ extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
 extern int synthesize_perf_probe_event(struct probe_point *pp);
 extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
 extern int synthesize_trace_kprobe_event(struct probe_point *pp);
-extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes);
+extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
+				    bool force_add);
 extern void del_trace_kprobe_events(struct strlist *dellist);
 extern void show_perf_probe_events(void);
 

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

* [tip:perf/urgent] perf probe: Support event name for --add option
  2009-12-15 15:28 ` [PATCH -tip 10/14] perf probe: Support event name for --add option Masami Hiramatsu
@ 2009-12-15 19:54   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 30+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2009-12-15 19:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, mingo, peterz, fweisbec, dle-develop, rostedt, jbaron,
	tglx, mhiramat, systemtap, linux-kernel, hpa, paulus, fche,
	jkenisto, hch, ananth, srikar, mingo, prasad

Commit-ID:  af663d75a64d2cc3f18bdb8a29ff4650b9417c16
Gitweb:     http://git.kernel.org/tip/af663d75a64d2cc3f18bdb8a29ff4650b9417c16
Author:     Masami Hiramatsu <mhiramat@redhat.com>
AuthorDate: Tue, 15 Dec 2009 10:32:18 -0500
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Tue, 15 Dec 2009 20:22:03 +0100

perf probe: Support event name for --add option

Support event name syntax for --add option. This allows
users to specify event name for each new event.

The --add syntax is:
 perf probe --add '[EVENT=]SRC:LINE ARGS'
or
 perf probe --add '[EVENT=]FUNC[+OFFS|%return|:RLN][@SRC] ARGS'

e.g.

 ./perf probe --add myprobe1=schedule

Note: currently group name is not supported yet, because it
can cause name-space confliction with other tracepoint/
hw-breakpoint events.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <20091215153218.17436.84675.stgit@dhcp-100-2-132.bos.redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 tools/perf/Documentation/perf-probe.txt |    3 +-
 tools/perf/builtin-probe.c              |    8 ++--
 tools/perf/util/probe-event.c           |   74 +++++++++++++++++++------------
 tools/perf/util/probe-event.h           |    3 +-
 tools/perf/util/probe-finder.h          |    3 +
 5 files changed, 55 insertions(+), 36 deletions(-)

diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index 8fa6bf9..250e391 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -49,8 +49,9 @@ PROBE SYNTAX
 ------------
 Probe points are defined by following syntax.
 
- "FUNC[+OFFS|:RLN|%return][@SRC]|SRC:ALN [ARG ...]"
+ "[EVENT=]FUNC[+OFFS|:RLN|%return][@SRC]|SRC:ALN [ARG ...]"
 
+'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'.
 'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, 'RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. In addition, 'SRC' specifies a source file which has that function.
 It is also possible to specify a probe point by the source line number by using 'SRC:ALN' syntax, where 'SRC' is the source file path and 'ALN' is the line number.
 'ARG' specifies the arguments of this probe point. You can use the name of local variable, or kprobe-tracer argument format (e.g. $retval, %ax, etc).
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 438a7bb..adc0a55 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -172,13 +172,13 @@ static const struct option options[] = {
 		opt_del_probe_event),
 	OPT_CALLBACK('a', "add", NULL,
 #ifdef NO_LIBDWARF
-		"FUNC[+OFFS|%return] [ARG ...]",
+		"[EVENT=]FUNC[+OFFS|%return] [ARG ...]",
 #else
-		"FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]",
+		"[EVENT=]FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]",
 #endif
 		"probe point definition, where\n"
-		"\t\tGRP:\tGroup name (optional)\n"
-		"\t\tNAME:\tEvent name\n"
+		"\t\tGROUP:\tGroup name (optional)\n"
+		"\t\tEVENT:\tEvent name\n"
 		"\t\tFUNC:\tFunction name\n"
 		"\t\tOFFS:\tOffset from function entry (in byte)\n"
 		"\t\t%return:\tPut the probe at function return\n"
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 5e99e52..3b4cf45 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -69,10 +69,23 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
 	char c, nc = 0;
 	/*
 	 * <Syntax>
-	 * perf probe SRC:LN
-	 * perf probe FUNC[+OFFS|%return][@SRC]
+	 * perf probe [EVENT=]SRC:LN
+	 * perf probe [EVENT=]FUNC[+OFFS|%return][@SRC]
+	 *
+	 * TODO:Group name support
 	 */
 
+	ptr = strchr(arg, '=');
+	if (ptr) {	/* Event name */
+		*ptr = '\0';
+		tmp = ptr + 1;
+		ptr = strchr(arg, ':');
+		if (ptr)	/* Group name is not supported yet. */
+			semantic_error("Group name is not supported yet.");
+		pp->event = strdup(arg);
+		arg = tmp;
+	}
+
 	ptr = strpbrk(arg, ":+@%");
 	if (ptr) {
 		nc = *ptr;
@@ -188,8 +201,7 @@ void parse_perf_probe_event(const char *str, struct probe_point *pp,
 }
 
 /* Parse kprobe_events event into struct probe_point */
-void parse_trace_kprobe_event(const char *str, char **group, char **event,
-			      struct probe_point *pp)
+void parse_trace_kprobe_event(const char *str, struct probe_point *pp)
 {
 	char pr;
 	char *p;
@@ -205,18 +217,17 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,
 
 	/* Scan event and group name. */
 	ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]",
-		     &pr, (float *)(void *)group, (float *)(void *)event);
+		     &pr, (float *)(void *)&pp->group,
+		     (float *)(void *)&pp->event);
 	if (ret != 3)
 		semantic_error("Failed to parse event name: %s", argv[0]);
-	pr_debug("Group:%s Event:%s probe:%c\n", *group, *event, pr);
-
-	if (!pp)
-		goto end;
+	pr_debug("Group:%s Event:%s probe:%c\n", pp->group, pp->event, pr);
 
 	pp->retprobe = (pr == 'r');
 
 	/* Scan function name and offset */
-	ret = sscanf(argv[1], "%a[^+]+%d", (float *)(void *)&pp->function, &pp->offset);
+	ret = sscanf(argv[1], "%a[^+]+%d", (float *)(void *)&pp->function,
+		     &pp->offset);
 	if (ret == 1)
 		pp->offset = 0;
 
@@ -235,7 +246,6 @@ void parse_trace_kprobe_event(const char *str, char **group, char **event,
 			die("Failed to copy argument.");
 	}
 
-end:
 	argv_free(argv);
 }
 
@@ -368,6 +378,10 @@ static void clear_probe_point(struct probe_point *pp)
 {
 	int i;
 
+	if (pp->event)
+		free(pp->event);
+	if (pp->group)
+		free(pp->group);
 	if (pp->function)
 		free(pp->function);
 	if (pp->file)
@@ -382,13 +396,13 @@ static void clear_probe_point(struct probe_point *pp)
 }
 
 /* Show an event */
-static void show_perf_probe_event(const char *group, const char *event,
-				  const char *place, struct probe_point *pp)
+static void show_perf_probe_event(const char *event, const char *place,
+				  struct probe_point *pp)
 {
 	int i, ret;
 	char buf[128];
 
-	ret = e_snprintf(buf, 128, "%s:%s", group, event);
+	ret = e_snprintf(buf, 128, "%s:%s", pp->group, event);
 	if (ret < 0)
 		die("Failed to copy event: %s", strerror(-ret));
 	printf("  %-40s (on %s", buf, place);
@@ -405,7 +419,6 @@ static void show_perf_probe_event(const char *group, const char *event,
 void show_perf_probe_events(void)
 {
 	int fd, nr;
-	char *group, *event;
 	struct probe_point pp;
 	struct strlist *rawlist;
 	struct str_node *ent;
@@ -415,16 +428,14 @@ void show_perf_probe_events(void)
 	close(fd);
 
 	strlist__for_each(ent, rawlist) {
-		parse_trace_kprobe_event(ent->s, &group, &event, &pp);
+		parse_trace_kprobe_event(ent->s, &pp);
 		/* Synthesize only event probe point */
 		nr = pp.nr_args;
 		pp.nr_args = 0;
 		synthesize_perf_probe_event(&pp);
 		pp.nr_args = nr;
 		/* Show an event */
-		show_perf_probe_event(group, event, pp.probes[0], &pp);
-		free(group);
-		free(event);
+		show_perf_probe_event(pp.event, pp.probes[0], &pp);
 		clear_probe_point(&pp);
 	}
 
@@ -434,24 +445,25 @@ void show_perf_probe_events(void)
 /* Get current perf-probe event names */
 static struct strlist *get_perf_event_names(int fd, bool include_group)
 {
-	char *group, *event;
 	char buf[128];
 	struct strlist *sl, *rawlist;
 	struct str_node *ent;
+	struct probe_point pp;
 
+	memset(&pp, 0, sizeof(pp));
 	rawlist = get_trace_kprobe_event_rawlist(fd);
 
 	sl = strlist__new(true, NULL);
 	strlist__for_each(ent, rawlist) {
-		parse_trace_kprobe_event(ent->s, &group, &event, NULL);
+		parse_trace_kprobe_event(ent->s, &pp);
 		if (include_group) {
-			if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
+			if (e_snprintf(buf, 128, "%s:%s", pp.group,
+				       pp.event) < 0)
 				die("Failed to copy group:event name.");
 			strlist__add(sl, buf);
 		} else
-			strlist__add(sl, event);
-		free(group);
-		free(event);
+			strlist__add(sl, pp.event);
+		clear_probe_point(&pp);
 	}
 
 	strlist__delete(rawlist);
@@ -507,19 +519,23 @@ void add_trace_kprobe_events(struct probe_point *probes, int nr_probes)
 
 	for (j = 0; j < nr_probes; j++) {
 		pp = probes + j;
+		if (!pp->event)
+			pp->event = strdup(pp->function);
+		if (!pp->group)
+			pp->group = strdup(PERFPROBE_GROUP);
+		DIE_IF(!pp->event || !pp->group);
 		for (i = 0; i < pp->found; i++) {
 			/* Get an unused new event name */
-			get_new_event_name(event, 64, pp->function, namelist);
+			get_new_event_name(event, 64, pp->event, namelist);
 			snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n",
 				 pp->retprobe ? 'r' : 'p',
-				 PERFPROBE_GROUP, event,
+				 pp->group, event,
 				 pp->probes[i]);
 			write_trace_kprobe_event(fd, buf);
 			printf("Added new event:\n");
 			/* Get the first parameter (probe-point) */
 			sscanf(pp->probes[i], "%s", buf);
-			show_perf_probe_event(PERFPROBE_GROUP, event,
-					      buf, pp);
+			show_perf_probe_event(event, buf, pp);
 			/* Add added event name to namelist */
 			strlist__add(namelist, event);
 		}
diff --git a/tools/perf/util/probe-event.h b/tools/perf/util/probe-event.h
index 028575b..8bb22f5 100644
--- a/tools/perf/util/probe-event.h
+++ b/tools/perf/util/probe-event.h
@@ -8,8 +8,7 @@
 extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
 				   bool *need_dwarf);
 extern int synthesize_perf_probe_event(struct probe_point *pp);
-extern void parse_trace_kprobe_event(const char *str, char **group,
-				     char **event, struct probe_point *pp);
+extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
 extern int synthesize_trace_kprobe_event(struct probe_point *pp);
 extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes);
 extern void del_trace_kprobe_events(struct strlist *dellist);
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index bdebca6..5e4050c 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -12,6 +12,9 @@ static inline int is_c_varname(const char *name)
 }
 
 struct probe_point {
+	char	*event;		/* Event name */
+	char	*group;		/* Event group */
+
 	/* Inputs */
 	char	*file;		/* File name */
 	int	line;		/* Line number */

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

end of thread, other threads:[~2009-12-15 19:54 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-15 15:26 [PATCH -tip 00/14] perf-probe updates Masami Hiramatsu
2009-12-15 15:26 ` [PATCH -tip 02/14] perf probe: Check the result of e_snprintf() Masami Hiramatsu
2009-12-15 19:26   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:26 ` [PATCH -tip 01/14] perf probe: Cleanup struct session in builtin-probe.c Masami Hiramatsu
2009-12-15 19:27   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:27 ` [PATCH -tip 09/14] perf probe: Add glob matching support on --del Masami Hiramatsu
2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:27 ` [PATCH -tip 05/14] perf probe: Fix --del to show info instead of warning Masami Hiramatsu
2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:27 ` [PATCH -tip 04/14] perf probe: Show need-dwarf message only if it is really needed Masami Hiramatsu
2009-12-15 19:27   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:27 ` [PATCH -tip 07/14] perf tools: Add for_each macros for strlist Masami Hiramatsu
2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:27 ` [PATCH -tip 06/14] perf probe: Fix --del to update current event list Masami Hiramatsu
2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:27 ` [PATCH -tip 03/14] perf probe: Check hyphen only argument Masami Hiramatsu
2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:27 ` [PATCH -tip 08/14] perf probe: Use strlist__for_each macros in probe-event.c Masami Hiramatsu
2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:28 ` [PATCH -tip 10/14] perf probe: Support event name for --add option Masami Hiramatsu
2009-12-15 19:54   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:28 ` [PATCH -tip 14/14] perf probe: Fix to show which probe point is not found Masami Hiramatsu
2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:28 ` [PATCH -tip 12/14] perf probe: Check build-id of vmlinux Masami Hiramatsu
2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:28 ` [PATCH -tip 11/14] perf probe: Reject second attempt of adding same-name event Masami Hiramatsu
2009-12-15 19:29   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 15:28 ` [PATCH -tip 13/14] perf probe: Check symbols in symtab/kallsyms Masami Hiramatsu
2009-12-15 19:28   ` [tip:perf/urgent] " tip-bot for Masami Hiramatsu
2009-12-15 19:23 ` [PATCH -tip 00/14] perf-probe updates Ingo Molnar

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 read-only IMAP folder(s) and NNTP newsgroup(s).