linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Andi Kleen <ak@linux.intel.com>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 3/8] perf tools: Add name term processing for alias
Date: Sat, 26 Jan 2013 21:04:05 +0100	[thread overview]
Message-ID: <1359230650-10415-4-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1359230650-10415-1-git-send-email-jolsa@redhat.com>

Adding support for name term being specified within
the alias definition and gives the name for the alias.

Alias could be now defined like:
  name=BR_MISP_EXEC.ALL_BRANCHES,event=0x89,umask=0xff

It'll be handy for having single file with multiple
alias definitions.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Stephane Eranian <eranian@google.com>
---
 tools/perf/util/parse-events.c | 19 ++-----------------
 tools/perf/util/pmu.c          | 35 +++++++++++++++++++++++++++++++++++
 tools/perf/util/pmu.h          |  3 +++
 3 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 83362f2..0143c90 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -616,22 +616,6 @@ int parse_events_add_numeric(struct list_head **list, int *idx,
 	return add_event(list, idx, &attr, NULL);
 }
 
-static int parse_events__is_name_term(struct parse_events_term *term)
-{
-	return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME;
-}
-
-static char *pmu_event_name(struct list_head *head_terms)
-{
-	struct parse_events_term *term;
-
-	list_for_each_entry(term, head_terms, list)
-		if (parse_events__is_name_term(term))
-			return term->val.str;
-
-	return NULL;
-}
-
 int parse_events_add_pmu(struct list_head **list, int *idx,
 			 char *name, struct list_head *head_config)
 {
@@ -656,7 +640,8 @@ int parse_events_add_pmu(struct list_head **list, int *idx,
 	if (perf_pmu__config(pmu, &attr, head_config))
 		return -EINVAL;
 
-	return __add_event(list, idx, &attr, pmu_event_name(head_config),
+	return __add_event(list, idx, &attr,
+			   perf_pmu__event_name(head_config, false),
 			   pmu->cpus);
 }
 
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index f7852e9..0d45ccd 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -95,6 +95,27 @@ static int pmu_format(char *name, struct list_head *format)
 	return 0;
 }
 
+static int parse_events__is_name_term(struct parse_events_term *term)
+{
+	return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME;
+}
+
+char *perf_pmu__event_name(struct list_head *head_terms, bool remove)
+{
+	struct parse_events_term *term;
+
+	list_for_each_entry(term, head_terms, list)
+		if (parse_events__is_name_term(term)) {
+			if (remove) {
+				list_del(&term->list);
+				free(term);
+			}
+			return term->val.str;
+		}
+
+	return NULL;
+}
+
 static int perf_pmu__new_alias(struct list_head *list, char *name, char *data)
 {
 	struct perf_pmu_alias *alias;
@@ -111,6 +132,20 @@ static int perf_pmu__new_alias(struct list_head *list, char *name, char *data)
 		return ret;
 	}
 
+	/*
+	 * Use NAME term to get alias name. In case there's no name
+	 * at all, bail out. In case we find NAME term, remove it
+	 * not to mangle with event term name.
+	 */
+	if (!name) {
+		name = perf_pmu__event_name(&alias->terms, true);
+
+		if (!name) {
+			free(alias);
+			return -EINVAL;
+		}
+	}
+
 	alias->name = strdup(name);
 	list_add_tail(&alias->list, list);
 	return 0;
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 32fe55b..54cd809 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -3,6 +3,7 @@
 
 #include <linux/bitops.h>
 #include <linux/perf_event.h>
+#include <stdbool.h>
 
 enum {
 	PERF_PMU_FORMAT_VALUE_CONFIG,
@@ -40,5 +41,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);
 
 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
 
+char *perf_pmu__event_name(struct list_head *head_terms, bool remove);
+
 int perf_pmu__test(void);
 #endif /* __PMU_H */
-- 
1.7.11.7


  parent reply	other threads:[~2013-01-26 20:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-26 20:04 [RFCv2 0/8] perf tools: Add non-architectural event aliases Jiri Olsa
2013-01-26 20:04 ` [PATCH 1/8] perf tools: Add '.' as part of the event 'name' token Jiri Olsa
2013-01-28 20:52   ` Stephane Eranian
2013-01-28 21:32     ` Stephane Eranian
2013-01-29  8:03       ` Ingo Molnar
2013-01-29 10:53         ` Jiri Olsa
2013-02-03 20:37         ` Stephane Eranian
2013-02-04  7:30           ` Jiri Olsa
2013-05-03 18:56       ` Peter Zijlstra
2013-05-04  8:10         ` Ingo Molnar
2013-01-26 20:04 ` [PATCH 2/8] perf tools: Change perf_pmu__new_alias function interface Jiri Olsa
2013-01-26 20:04 ` Jiri Olsa [this message]
2013-01-26 20:04 ` [PATCH 4/8] perf tools: Add pmu interface to parse single file of aliases Jiri Olsa
2013-01-26 20:04 ` [PATCH 5/8] perf tools: Add support to include non architectural event aliases Jiri Olsa
2013-01-26 20:04 ` [PATCH 6/8] perf tools: Add non arch events for SandyBridge microarchitecture Jiri Olsa
2013-01-26 20:04 ` [PATCH 7/8] perf tools: Add non arch events for IvyBridge micro architecture Jiri Olsa
2013-01-26 20:04 ` [PATCH 8/8] perf tools: List kernel supplied event aliases in perf list v2 Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1359230650-10415-4-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).