All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 12/20] perf pmu: Expand PMU events by prefix match
Date: Fri, 24 Mar 2017 11:57:23 -0300	[thread overview]
Message-ID: <20170324145731.29350-13-acme@kernel.org> (raw)
In-Reply-To: <20170324145731.29350-1-acme@kernel.org>

From: Andi Kleen <ak@linux.intel.com>

When the user specifies a pmu directly, expand it automatically with a
prefix match for all available PMUs, similar as we do for the normal
aliases now.

This allows to specify attributes for duplicated boxes quickly.  For
example uncore_cbox_{0,6}/.../ can be now specified as uncore_cbox/.../
and it gets automatically expanded for all boxes.

This generally makes it more concise to write uncore specifications, and
also avoids the need to know the exact topology of the system.

Before:

  % perf stat -a -e uncore_cbox_0/event=0x35,umask=0x1,filter_opc=0x19C/,\
  uncore_cbox_1/event=0x35,umask=0x1,filter_opc=0x19C/,\
  uncore_cbox_2/event=0x35,umask=0x1,filter_opc=0x19C/,\
  uncore_cbox_3/event=0x35,umask=0x1,filter_opc=0x19C/,\
  uncore_cbox_4/event=0x35,umask=0x1,filter_opc=0x19C/,\
  uncore_cbox_5/event=0x35,umask=0x1,filter_opc=0x19C/ sleep 1

After:

  % perf stat -a -e uncore_cbox/event=0x35,umask=0x1,filter_opc=0x19C/ sleep 1

v2: Handle all bison rules. Move multi add code to separate function.
    Handle uncore_ prefix correctly.
v3: Move parse_events_multi_pmu_add to separate patch. Move uncore
    prefix check to separate patch.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-6-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/parse-events.c | 25 +++++++++++++++++++++++++
 tools/perf/util/parse-events.h |  3 +++
 tools/perf/util/parse-events.y | 40 ++++++++++++++++++++++++++--------------
 3 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index c3edb373ed86..e594c974c93e 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2462,6 +2462,31 @@ int parse_events_term__clone(struct parse_events_term **new,
 	return new_term(new, &temp, term->val.str, term->val.num);
 }
 
+int parse_events_copy_term_list(struct list_head *old,
+				 struct list_head **new)
+{
+	struct parse_events_term *term, *n;
+	int ret;
+
+	if (!old) {
+		*new = NULL;
+		return 0;
+	}
+
+	*new = malloc(sizeof(struct list_head));
+	if (!*new)
+		return -ENOMEM;
+	INIT_LIST_HEAD(*new);
+
+	list_for_each_entry (term, old, list) {
+		ret = parse_events_term__clone(&n, term);
+		if (ret)
+			return ret;
+		list_add_tail(&n->list, *new);
+	}
+	return 0;
+}
+
 void parse_events_terms__purge(struct list_head *terms)
 {
 	struct parse_events_term *term, *h;
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index deca9ce965a7..f38086b8dbea 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -172,6 +172,9 @@ int parse_events_multi_pmu_add(struct parse_events_evlist *data,
 			       char *str,
 			       struct list_head **listp);
 
+int parse_events_copy_term_list(struct list_head *old,
+				 struct list_head **new);
+
 enum perf_pmu_event_symbol_type
 perf_pmu__parse_check(const char *name);
 void parse_events__set_leader(char *name, struct list_head *list);
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 36af02f95243..20935b17753d 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -226,11 +226,32 @@ event_pmu:
 PE_NAME opt_event_config
 {
 	struct parse_events_evlist *data = _data;
-	struct list_head *list;
+	struct list_head *list, *orig_terms, *terms;
+
+	if (parse_events_copy_term_list($2, &orig_terms))
+		YYABORT;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_pmu(data, list, $1, $2));
+	if (parse_events_add_pmu(data, list, $1, $2)) {
+		struct perf_pmu *pmu = NULL;
+		int ok = 0;
+
+		while ((pmu = perf_pmu__scan(pmu)) != NULL) {
+			char *name = pmu->name;
+
+			if (!strncmp($1, name, strlen($1))) {
+				if (parse_events_copy_term_list(orig_terms, &terms))
+					YYABORT;
+				if (!parse_events_add_pmu(data, list, pmu->name, terms))
+					ok++;
+				parse_events_terms__delete(terms);
+			}
+		}
+		if (!ok)
+			YYABORT;
+	}
 	parse_events_terms__delete($2);
+	parse_events_terms__delete(orig_terms);
 	$$ = list;
 }
 |
@@ -245,21 +266,12 @@ PE_KERNEL_PMU_EVENT sep_dc
 |
 PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
 {
-	struct parse_events_evlist *data = _data;
-	struct list_head *head;
-	struct parse_events_term *term;
 	struct list_head *list;
 	char pmu_name[128];
-	snprintf(&pmu_name, 128, "%s-%s", $1, $3);
 
-	ALLOC_LIST(head);
-	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
-					&pmu_name, 1, false, &@1, NULL));
-	list_add_tail(&term->list, head);
-
-	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_pmu(data, list, "cpu", head));
-	parse_events_terms__delete(head);
+	snprintf(&pmu_name, 128, "%s-%s", $1, $3);
+	if (parse_events_multi_pmu_add(_data, pmu_name, &list) < 0)
+		YYABORT;
 	$$ = list;
 }
 
-- 
2.9.3

  parent reply	other threads:[~2017-03-24 15:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 14:57 [GIT PULL 00/20] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-03-24 14:57 ` Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 01/20] perf probe: Change MAX_CMDLEN Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 02/20] perf probe: Return errno when not hitting any event Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 03/20] perf sdt: Add scanning of sdt probes arguments Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 04/20] perf probe: Add sdt probes arguments into the uprobe cmd string Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 05/20] perf sdt x86: Add renaming logic for rNN and other registers Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 06/20] perf annotate: More exactly grep -v of the objdump command Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 07/20] perf annotate: Add comment clarifying how the source code line is parsed Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 08/20] perf stat: Factor out callback for collecting event values Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 09/20] perf stat: Collapse identically named events Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 10/20] perf stat: Handle partially bad results with merging Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 11/20] perf tools: Factor out PMU matching in parser Arnaldo Carvalho de Melo
2017-03-24 14:57 ` Arnaldo Carvalho de Melo [this message]
2017-03-24 14:57 ` [PATCH 13/20] perf pmu: Special case uncore_ prefix Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 14/20] perf tools: Add a simple expression parser for JSON Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 15/20] perf vendor events intel: Update Intel uncore JSON event files Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 16/20] perf pmu: Support MetricExpr header in JSON event list Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 17/20] perf stat: Output JSON MetricExpr metric Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 18/20] perf list: Support printing MetricExpr with --debug Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 19/20] perf pmu: Add support for MetricName JSON attribute Arnaldo Carvalho de Melo
2017-03-24 14:57 ` [PATCH 20/20] perf list: Move extra details printing to new option Arnaldo Carvalho de Melo
2017-03-24 18:39 ` [GIT PULL 00/20] perf/core improvements and fixes Ingo Molnar
2017-03-24 18:39   ` Ingo Molnar

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20170324145731.29350-13-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.