aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2017-01-27 21:03:39 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-02-08 06:55:04 -0500
commit231bb2aa32498cbebef1306889a02114e9dfc934 (patch)
tree0588a93a35a6f8ef982488a93f5b26063e85756c /tools/perf
parent15b22ed369aa23ef4d083ffb9621650c353d3ddd (diff)
perf pmu: Support event aliases for non cpu// pmus
The code for handling pmu aliases without specifying the PMU hardcoded only supported the cpu PMU. This patch extends it to work for all PMUs. We always duplicate the event for all PMUs that have an matching alias. This allows to automatically expand an alias for all instances of a PMU (so for example you can monitor all cache boxes with a single event) Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20170128020345.19007-5-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/parse-events.c46
-rw-r--r--tools/perf/util/parse-events.y32
2 files changed, 51 insertions, 27 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 3c876b8ba4de..6dbcba7f0969 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1504,35 +1504,41 @@ static void perf_pmu__parse_init(void)
1504 struct perf_pmu_alias *alias; 1504 struct perf_pmu_alias *alias;
1505 int len = 0; 1505 int len = 0;
1506 1506
1507 pmu = perf_pmu__find("cpu"); 1507 pmu = NULL;
1508 if ((pmu == NULL) || list_empty(&pmu->aliases)) { 1508 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1509 list_for_each_entry(alias, &pmu->aliases, list) {
1510 if (strchr(alias->name, '-'))
1511 len++;
1512 len++;
1513 }
1514 }
1515
1516 if (len == 0) {
1509 perf_pmu_events_list_num = -1; 1517 perf_pmu_events_list_num = -1;
1510 return; 1518 return;
1511 } 1519 }
1512 list_for_each_entry(alias, &pmu->aliases, list) {
1513 if (strchr(alias->name, '-'))
1514 len++;
1515 len++;
1516 }
1517 perf_pmu_events_list = malloc(sizeof(struct perf_pmu_event_symbol) * len); 1520 perf_pmu_events_list = malloc(sizeof(struct perf_pmu_event_symbol) * len);
1518 if (!perf_pmu_events_list) 1521 if (!perf_pmu_events_list)
1519 return; 1522 return;
1520 perf_pmu_events_list_num = len; 1523 perf_pmu_events_list_num = len;
1521 1524
1522 len = 0; 1525 len = 0;
1523 list_for_each_entry(alias, &pmu->aliases, list) { 1526 pmu = NULL;
1524 struct perf_pmu_event_symbol *p = perf_pmu_events_list + len; 1527 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1525 char *tmp = strchr(alias->name, '-'); 1528 list_for_each_entry(alias, &pmu->aliases, list) {
1526 1529 struct perf_pmu_event_symbol *p = perf_pmu_events_list + len;
1527 if (tmp != NULL) { 1530 char *tmp = strchr(alias->name, '-');
1528 SET_SYMBOL(strndup(alias->name, tmp - alias->name), 1531
1529 PMU_EVENT_SYMBOL_PREFIX); 1532 if (tmp != NULL) {
1530 p++; 1533 SET_SYMBOL(strndup(alias->name, tmp - alias->name),
1531 SET_SYMBOL(strdup(++tmp), PMU_EVENT_SYMBOL_SUFFIX); 1534 PMU_EVENT_SYMBOL_PREFIX);
1532 len += 2; 1535 p++;
1533 } else { 1536 SET_SYMBOL(strdup(++tmp), PMU_EVENT_SYMBOL_SUFFIX);
1534 SET_SYMBOL(strdup(alias->name), PMU_EVENT_SYMBOL); 1537 len += 2;
1535 len++; 1538 } else {
1539 SET_SYMBOL(strdup(alias->name), PMU_EVENT_SYMBOL);
1540 len++;
1541 }
1536 } 1542 }
1537 } 1543 }
1538 qsort(perf_pmu_events_list, len, 1544 qsort(perf_pmu_events_list, len,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 879115f93edc..f3b5ec901600 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -12,6 +12,7 @@
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include "util.h" 14#include "util.h"
15#include "pmu.h"
15#include "parse-events.h" 16#include "parse-events.h"
16#include "parse-events-bison.h" 17#include "parse-events-bison.h"
17 18
@@ -236,15 +237,32 @@ PE_KERNEL_PMU_EVENT sep_dc
236 struct list_head *head; 237 struct list_head *head;
237 struct parse_events_term *term; 238 struct parse_events_term *term;
238 struct list_head *list; 239 struct list_head *list;
240 struct perf_pmu *pmu = NULL;
241 int ok = 0;
239 242
240 ALLOC_LIST(head); 243 /* Add it for all PMUs that support the alias */
241 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
242 $1, 1, &@1, NULL));
243 list_add_tail(&term->list, head);
244
245 ALLOC_LIST(list); 244 ALLOC_LIST(list);
246 ABORT_ON(parse_events_add_pmu(data, list, "cpu", head)); 245 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
247 parse_events_terms__delete(head); 246 struct perf_pmu_alias *alias;
247
248 list_for_each_entry(alias, &pmu->aliases, list) {
249 if (!strcasecmp(alias->name, $1)) {
250 ALLOC_LIST(head);
251 ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
252 $1, 1, &@1, NULL));
253 list_add_tail(&term->list, head);
254
255 if (!parse_events_add_pmu(data, list,
256 pmu->name, head)) {
257 ok++;
258 }
259
260 parse_events_terms__delete(head);
261 }
262 }
263 }
264 if (!ok)
265 YYABORT;
248 $$ = list; 266 $$ = list;
249} 267}
250| 268|