aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-05-21 03:12:53 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-05-22 10:47:54 -0400
commit6b5fc39bdd781711d7da8b95ae0243df3b35c5bf (patch)
tree95b7a6062e5170da6121cd8486b0e4c7a921cf70 /tools
parent08d2f762ac4af861b962e543fceab341f05c8886 (diff)
perf tools: Add hardcoded name term for pmu events
Adding a new hardcoded term 'name' allowing to specify a name for the pmu event. The term is defined along with standard pmu terms. If no 'name' term is given, the event name follows following template: "raw 0x<perf_event_attr::config>" running: perf stat -e cpu/config=1,name=krava1/u ls will produce following output: ... Performance counter stats for 'ls': 0 krava1 ... running: perf stat -e cpu/config=1/u ls will produce following output: ... Performance counter stats for 'ls': 0 raw 0x1 ... 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: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1337584373-2741-6-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/parse-events-test.c25
-rw-r--r--tools/perf/util/parse-events.c23
-rw-r--r--tools/perf/util/parse-events.h1
-rw-r--r--tools/perf/util/parse-events.l1
-rw-r--r--tools/perf/util/parse-events.y8
-rw-r--r--tools/perf/util/pmu.c4
6 files changed, 59 insertions, 3 deletions
diff --git a/tools/perf/util/parse-events-test.c b/tools/perf/util/parse-events-test.c
index 2e8f435384a6..76b98e2a587d 100644
--- a/tools/perf/util/parse-events-test.c
+++ b/tools/perf/util/parse-events-test.c
@@ -409,6 +409,27 @@ static int test__checkevent_list(struct perf_evlist *evlist)
409 return 0; 409 return 0;
410} 410}
411 411
412static int test__checkevent_pmu_name(struct perf_evlist *evlist)
413{
414 struct perf_evsel *evsel;
415
416 /* cpu/config=1,name=krava1/u */
417 evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
418 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
419 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
420 TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
421 TEST_ASSERT_VAL("wrong name", !strcmp(evsel->name, "krava"));
422
423 /* cpu/config=2/" */
424 evsel = list_entry(evsel->node.next, struct perf_evsel, node);
425 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
426 TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
427 TEST_ASSERT_VAL("wrong config", 2 == evsel->attr.config);
428 TEST_ASSERT_VAL("wrong name", !strcmp(evsel->name, "raw 0x2"));
429
430 return 0;
431}
432
412struct test__event_st { 433struct test__event_st {
413 const char *name; 434 const char *name;
414 __u32 type; 435 __u32 type;
@@ -529,6 +550,10 @@ static struct test__event_st test__events_pmu[] = {
529 .name = "cpu/config=10,config1,config2=3,period=1000/u", 550 .name = "cpu/config=10,config1,config2=3,period=1000/u",
530 .check = test__checkevent_pmu, 551 .check = test__checkevent_pmu,
531 }, 552 },
553 [1] = {
554 .name = "cpu/config=1,name=krava/u,cpu/config=2/u",
555 .check = test__checkevent_pmu_name,
556 },
532}; 557};
533 558
534#define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \ 559#define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 59324e7b3d8e..fac7d59309b8 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -634,6 +634,9 @@ do { \
634 * attr->branch_sample_type = term->val.num; 634 * attr->branch_sample_type = term->val.num;
635 */ 635 */
636 break; 636 break;
637 case PARSE_EVENTS__TERM_TYPE_NAME:
638 CHECK_TYPE_VAL(STR);
639 break;
637 default: 640 default:
638 return -EINVAL; 641 return -EINVAL;
639 } 642 }
@@ -672,6 +675,23 @@ int parse_events_add_numeric(struct list_head **list, int *idx,
672 (char *) __event_name(type, config)); 675 (char *) __event_name(type, config));
673} 676}
674 677
678static int parse_events__is_name_term(struct parse_events__term *term)
679{
680 return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME;
681}
682
683static char *pmu_event_name(struct perf_event_attr *attr,
684 struct list_head *head_terms)
685{
686 struct parse_events__term *term;
687
688 list_for_each_entry(term, head_terms, list)
689 if (parse_events__is_name_term(term))
690 return term->val.str;
691
692 return (char *) __event_name(PERF_TYPE_RAW, attr->config);
693}
694
675int parse_events_add_pmu(struct list_head **list, int *idx, 695int parse_events_add_pmu(struct list_head **list, int *idx,
676 char *name, struct list_head *head_config) 696 char *name, struct list_head *head_config)
677{ 697{
@@ -693,7 +713,8 @@ int parse_events_add_pmu(struct list_head **list, int *idx,
693 if (perf_pmu__config(pmu, &attr, head_config)) 713 if (perf_pmu__config(pmu, &attr, head_config))
694 return -EINVAL; 714 return -EINVAL;
695 715
696 return add_event(list, idx, &attr, (char *) "pmu"); 716 return add_event(list, idx, &attr,
717 pmu_event_name(&attr, head_config));
697} 718}
698 719
699void parse_events_update_lists(struct list_head *list_event, 720void parse_events_update_lists(struct list_head *list_event,
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 25ae3732f5b0..8cac57ab4ee6 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -47,6 +47,7 @@ enum {
47 PARSE_EVENTS__TERM_TYPE_CONFIG, 47 PARSE_EVENTS__TERM_TYPE_CONFIG,
48 PARSE_EVENTS__TERM_TYPE_CONFIG1, 48 PARSE_EVENTS__TERM_TYPE_CONFIG1,
49 PARSE_EVENTS__TERM_TYPE_CONFIG2, 49 PARSE_EVENTS__TERM_TYPE_CONFIG2,
50 PARSE_EVENTS__TERM_TYPE_NAME,
50 PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD, 51 PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD,
51 PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE, 52 PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE,
52}; 53};
diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 331d28a08dcb..618a8e788399 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -105,6 +105,7 @@ misses|miss { return str(PE_NAME_CACHE_OP_RESULT); }
105config { return term(PARSE_EVENTS__TERM_TYPE_CONFIG); } 105config { return term(PARSE_EVENTS__TERM_TYPE_CONFIG); }
106config1 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG1); } 106config1 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG1); }
107config2 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG2); } 107config2 { return term(PARSE_EVENTS__TERM_TYPE_CONFIG2); }
108name { return term(PARSE_EVENTS__TERM_TYPE_NAME); }
108period { return term(PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); } 109period { return term(PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
109branch_type { return term(PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); } 110branch_type { return term(PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
110 111
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 126fad0a9936..362cc59332ae 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -237,6 +237,14 @@ PE_NAME
237 $$ = term; 237 $$ = term;
238} 238}
239| 239|
240PE_TERM '=' PE_NAME
241{
242 struct parse_events__term *term;
243
244 ABORT_ON(parse_events__term_str(&term, $1, NULL, $3));
245 $$ = term;
246}
247|
240PE_TERM '=' PE_VALUE 248PE_TERM '=' PE_VALUE
241{ 249{
242 struct parse_events__term *term; 250 struct parse_events__term *term;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 8ee219b7285b..a119a5371699 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -258,9 +258,9 @@ static int pmu_config_term(struct list_head *formats,
258static int pmu_config(struct list_head *formats, struct perf_event_attr *attr, 258static int pmu_config(struct list_head *formats, struct perf_event_attr *attr,
259 struct list_head *head_terms) 259 struct list_head *head_terms)
260{ 260{
261 struct parse_events__term *term, *h; 261 struct parse_events__term *term;
262 262
263 list_for_each_entry_safe(term, h, head_terms, list) 263 list_for_each_entry(term, head_terms, list)
264 if (pmu_config_term(formats, attr, term)) 264 if (pmu_config_term(formats, attr, term))
265 return -EINVAL; 265 return -EINVAL;
266 266