diff options
author | Wang Nan <wangnan0@huawei.com> | 2016-02-19 06:44:01 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-02-19 17:12:51 -0500 |
commit | 43d0b97817a41b274aaec0476e912dae3ae1f93d (patch) | |
tree | f865dd5a4fce34a7ad911bdfb30ee91f80c859d9 | |
parent | 10bf358a1b79fa1311eb05ee31f2cefdcad01741 (diff) |
perf tools: Enable config and setting names for legacy cache events
This patch allows setting config terms for legacy cache events.
For example:
# perf stat -e L1-icache-misses/name=valA/ -e branches/name=valB/ ls
...
Performance counter stats for 'ls':
11299 valA
451605 valB
0.000779091 seconds time elapsed
# perf record -e cache-misses/name=inh/ -e cache-misses/name=noinh,no-inherit/ bash
# ls
# exit
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.023 MB perf.data (131 samples) ]
# perf report --stdio | grep -B 1 'Event count'
# Samples: 105 of event 'inh'
# Event count (approx.): 109118
--
# Samples: 26 of event 'noinh'
# Event count (approx.): 48302
A test case is introduced to test this feature.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Cody P Schafer <dev@codyps.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kirill Smelkov <kirr@nexedi.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1455882283-79592-14-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/tests/parse-events.c | 12 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 30 | ||||
-rw-r--r-- | tools/perf/util/parse-events.h | 4 | ||||
-rw-r--r-- | tools/perf/util/parse-events.y | 18 |
4 files changed, 54 insertions, 10 deletions
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 15e2d055321e..7865f68dc0d8 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c | |||
@@ -1295,6 +1295,13 @@ static int test__checkevent_config_num(struct perf_evlist *evlist) | |||
1295 | return 0; | 1295 | return 0; |
1296 | } | 1296 | } |
1297 | 1297 | ||
1298 | static int test__checkevent_config_cache(struct perf_evlist *evlist) | ||
1299 | { | ||
1300 | struct perf_evsel *evsel = perf_evlist__first(evlist); | ||
1301 | |||
1302 | TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "cachepmu") == 0); | ||
1303 | return 0; | ||
1304 | } | ||
1298 | 1305 | ||
1299 | static int count_tracepoints(void) | 1306 | static int count_tracepoints(void) |
1300 | { | 1307 | { |
@@ -1619,6 +1626,11 @@ static struct evlist_test test__events[] = { | |||
1619 | .check = test__checkevent_config_num, | 1626 | .check = test__checkevent_config_num, |
1620 | .id = 50, | 1627 | .id = 50, |
1621 | }, | 1628 | }, |
1629 | { | ||
1630 | .name = "L1-dcache-misses/name=cachepmu/", | ||
1631 | .check = test__checkevent_config_cache, | ||
1632 | .id = 51, | ||
1633 | }, | ||
1622 | }; | 1634 | }; |
1623 | 1635 | ||
1624 | static struct evlist_test test__events_pmu[] = { | 1636 | static struct evlist_test test__events_pmu[] = { |
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 75576e130e16..2996aa4207bd 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -350,11 +350,25 @@ static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES] | |||
350 | return -1; | 350 | return -1; |
351 | } | 351 | } |
352 | 352 | ||
353 | typedef int config_term_func_t(struct perf_event_attr *attr, | ||
354 | struct parse_events_term *term, | ||
355 | struct parse_events_error *err); | ||
356 | static int config_term_common(struct perf_event_attr *attr, | ||
357 | struct parse_events_term *term, | ||
358 | struct parse_events_error *err); | ||
359 | static int config_attr(struct perf_event_attr *attr, | ||
360 | struct list_head *head, | ||
361 | struct parse_events_error *err, | ||
362 | config_term_func_t config_term); | ||
363 | |||
353 | int parse_events_add_cache(struct list_head *list, int *idx, | 364 | int parse_events_add_cache(struct list_head *list, int *idx, |
354 | char *type, char *op_result1, char *op_result2) | 365 | char *type, char *op_result1, char *op_result2, |
366 | struct parse_events_error *error, | ||
367 | struct list_head *head_config) | ||
355 | { | 368 | { |
356 | struct perf_event_attr attr; | 369 | struct perf_event_attr attr; |
357 | char name[MAX_NAME_LEN]; | 370 | LIST_HEAD(config_terms); |
371 | char name[MAX_NAME_LEN], *config_name; | ||
358 | int cache_type = -1, cache_op = -1, cache_result = -1; | 372 | int cache_type = -1, cache_op = -1, cache_result = -1; |
359 | char *op_result[2] = { op_result1, op_result2 }; | 373 | char *op_result[2] = { op_result1, op_result2 }; |
360 | int i, n; | 374 | int i, n; |
@@ -368,6 +382,7 @@ int parse_events_add_cache(struct list_head *list, int *idx, | |||
368 | if (cache_type == -1) | 382 | if (cache_type == -1) |
369 | return -EINVAL; | 383 | return -EINVAL; |
370 | 384 | ||
385 | config_name = get_config_name(head_config); | ||
371 | n = snprintf(name, MAX_NAME_LEN, "%s", type); | 386 | n = snprintf(name, MAX_NAME_LEN, "%s", type); |
372 | 387 | ||
373 | for (i = 0; (i < 2) && (op_result[i]); i++) { | 388 | for (i = 0; (i < 2) && (op_result[i]); i++) { |
@@ -408,7 +423,16 @@ int parse_events_add_cache(struct list_head *list, int *idx, | |||
408 | memset(&attr, 0, sizeof(attr)); | 423 | memset(&attr, 0, sizeof(attr)); |
409 | attr.config = cache_type | (cache_op << 8) | (cache_result << 16); | 424 | attr.config = cache_type | (cache_op << 8) | (cache_result << 16); |
410 | attr.type = PERF_TYPE_HW_CACHE; | 425 | attr.type = PERF_TYPE_HW_CACHE; |
411 | return add_event(list, idx, &attr, name, NULL); | 426 | |
427 | if (head_config) { | ||
428 | if (config_attr(&attr, head_config, error, | ||
429 | config_term_common)) | ||
430 | return -EINVAL; | ||
431 | |||
432 | if (get_config_terms(head_config, &config_terms)) | ||
433 | return -ENOMEM; | ||
434 | } | ||
435 | return add_event(list, idx, &attr, config_name ? : name, &config_terms); | ||
412 | } | 436 | } |
413 | 437 | ||
414 | static void tracepoint_error(struct parse_events_error *e, int err, | 438 | static void tracepoint_error(struct parse_events_error *e, int err, |
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 76151f9f00d2..d5eb2af78826 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h | |||
@@ -140,7 +140,9 @@ int parse_events_add_numeric(struct parse_events_evlist *data, | |||
140 | u32 type, u64 config, | 140 | u32 type, u64 config, |
141 | struct list_head *head_config); | 141 | struct list_head *head_config); |
142 | int parse_events_add_cache(struct list_head *list, int *idx, | 142 | int parse_events_add_cache(struct list_head *list, int *idx, |
143 | char *type, char *op_result1, char *op_result2); | 143 | char *type, char *op_result1, char *op_result2, |
144 | struct parse_events_error *error, | ||
145 | struct list_head *head_config); | ||
144 | int parse_events_add_breakpoint(struct list_head *list, int *idx, | 146 | int parse_events_add_breakpoint(struct list_head *list, int *idx, |
145 | void *ptr, char *type, u64 len); | 147 | void *ptr, char *type, u64 len); |
146 | int parse_events_add_pmu(struct parse_events_evlist *data, | 148 | int parse_events_add_pmu(struct parse_events_evlist *data, |
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 82029f92c4d2..6a2d006ea77f 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y | |||
@@ -293,33 +293,39 @@ value_sym sep_slash_dc | |||
293 | } | 293 | } |
294 | 294 | ||
295 | event_legacy_cache: | 295 | event_legacy_cache: |
296 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT | 296 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config |
297 | { | 297 | { |
298 | struct parse_events_evlist *data = _data; | 298 | struct parse_events_evlist *data = _data; |
299 | struct parse_events_error *error = data->error; | ||
299 | struct list_head *list; | 300 | struct list_head *list; |
300 | 301 | ||
301 | ALLOC_LIST(list); | 302 | ALLOC_LIST(list); |
302 | ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5)); | 303 | ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5, error, $6)); |
304 | parse_events_terms__delete($6); | ||
303 | $$ = list; | 305 | $$ = list; |
304 | } | 306 | } |
305 | | | 307 | | |
306 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT | 308 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config |
307 | { | 309 | { |
308 | struct parse_events_evlist *data = _data; | 310 | struct parse_events_evlist *data = _data; |
311 | struct parse_events_error *error = data->error; | ||
309 | struct list_head *list; | 312 | struct list_head *list; |
310 | 313 | ||
311 | ALLOC_LIST(list); | 314 | ALLOC_LIST(list); |
312 | ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL)); | 315 | ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL, error, $4)); |
316 | parse_events_terms__delete($4); | ||
313 | $$ = list; | 317 | $$ = list; |
314 | } | 318 | } |
315 | | | 319 | | |
316 | PE_NAME_CACHE_TYPE | 320 | PE_NAME_CACHE_TYPE opt_event_config |
317 | { | 321 | { |
318 | struct parse_events_evlist *data = _data; | 322 | struct parse_events_evlist *data = _data; |
323 | struct parse_events_error *error = data->error; | ||
319 | struct list_head *list; | 324 | struct list_head *list; |
320 | 325 | ||
321 | ALLOC_LIST(list); | 326 | ALLOC_LIST(list); |
322 | ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL)); | 327 | ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL, error, $2)); |
328 | parse_events_terms__delete($2); | ||
323 | $$ = list; | 329 | $$ = list; |
324 | } | 330 | } |
325 | 331 | ||