aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/parse-events.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2015-04-22 15:10:22 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-04-29 09:38:01 -0400
commit3b0e371cc05dfb624f990ea5e1da2bff615adaef (patch)
tree9d1065fcfc215961674a4e9fbb0588865a177755 /tools/perf/util/parse-events.c
parente64b020ba1adfd081a26c5a35a2990f91da043a0 (diff)
perf tools: Add static terms support for parse_events_error
Allowing static terms like 'name,period,config,config1..' processing to report back error. $ perf record -e 'cpu/event=1,name=1/' ls event syntax error: '..=1,name=1/' \___ expected string value $ perf record -e 'cpu/event=1,period=krava/' ls event syntax error: '..,period=krava/' \___ expected numeric value $ perf record -e 'cpu/config=krava1/' ls event syntax error: '../config=krava1/' \___ expected numeric value Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1429729824-13932-8-git-send-email-jolsa@kernel.org [ Renamed 'error' variables to 'err', not to clash with util.h error() ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r--tools/perf/util/parse-events.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 1d810d1fc726..278aebe5d65b 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -545,13 +545,31 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
545 return add_event(list, idx, &attr, NULL); 545 return add_event(list, idx, &attr, NULL);
546} 546}
547 547
548static int check_type_val(struct parse_events_term *term,
549 struct parse_events_error *err,
550 int type)
551{
552 if (type == term->type_val)
553 return 0;
554
555 if (err) {
556 err->idx = term->err_val;
557 if (type == PARSE_EVENTS__TERM_TYPE_NUM)
558 err->str = strdup("expected numeric value");
559 else
560 err->str = strdup("expected string value");
561 }
562 return -EINVAL;
563}
564
548static int config_term(struct perf_event_attr *attr, 565static int config_term(struct perf_event_attr *attr,
549 struct parse_events_term *term) 566 struct parse_events_term *term,
567 struct parse_events_error *err)
550{ 568{
551#define CHECK_TYPE_VAL(type) \ 569#define CHECK_TYPE_VAL(type) \
552do { \ 570do { \
553 if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \ 571 if (check_type_val(term, err, PARSE_EVENTS__TERM_TYPE_ ## type)) \
554 return -EINVAL; \ 572 return -EINVAL; \
555} while (0) 573} while (0)
556 574
557 switch (term->type_term) { 575 switch (term->type_term) {
@@ -595,12 +613,13 @@ do { \
595} 613}
596 614
597static int config_attr(struct perf_event_attr *attr, 615static int config_attr(struct perf_event_attr *attr,
598 struct list_head *head) 616 struct list_head *head,
617 struct parse_events_error *err)
599{ 618{
600 struct parse_events_term *term; 619 struct parse_events_term *term;
601 620
602 list_for_each_entry(term, head, list) 621 list_for_each_entry(term, head, list)
603 if (config_term(attr, term)) 622 if (config_term(attr, term, err))
604 return -EINVAL; 623 return -EINVAL;
605 624
606 return 0; 625 return 0;
@@ -617,7 +636,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx,
617 attr.config = config; 636 attr.config = config;
618 637
619 if (head_config && 638 if (head_config &&
620 config_attr(&attr, head_config)) 639 config_attr(&attr, head_config, NULL))
621 return -EINVAL; 640 return -EINVAL;
622 641
623 return add_event(list, idx, &attr, NULL); 642 return add_event(list, idx, &attr, NULL);
@@ -672,7 +691,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
672 * Configure hardcoded terms first, no need to check 691 * Configure hardcoded terms first, no need to check
673 * return value when called with fail == 0 ;) 692 * return value when called with fail == 0 ;)
674 */ 693 */
675 if (config_attr(&attr, head_config)) 694 if (config_attr(&attr, head_config, data->error))
676 return -EINVAL; 695 return -EINVAL;
677 696
678 if (perf_pmu__config(pmu, &attr, head_config, data->error)) 697 if (perf_pmu__config(pmu, &attr, head_config, data->error))