aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/parse-events.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r--tools/perf/util/parse-events.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5b3a0ef4e232..c7fc18a33d54 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -593,17 +593,27 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
593static int config_term(struct perf_event_attr *attr, 593static int config_term(struct perf_event_attr *attr,
594 struct parse_events__term *term) 594 struct parse_events__term *term)
595{ 595{
596 switch (term->type) { 596#define CHECK_TYPE_VAL(type) \
597do { \
598 if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \
599 return -EINVAL; \
600} while (0)
601
602 switch (term->type_term) {
597 case PARSE_EVENTS__TERM_TYPE_CONFIG: 603 case PARSE_EVENTS__TERM_TYPE_CONFIG:
604 CHECK_TYPE_VAL(NUM);
598 attr->config = term->val.num; 605 attr->config = term->val.num;
599 break; 606 break;
600 case PARSE_EVENTS__TERM_TYPE_CONFIG1: 607 case PARSE_EVENTS__TERM_TYPE_CONFIG1:
608 CHECK_TYPE_VAL(NUM);
601 attr->config1 = term->val.num; 609 attr->config1 = term->val.num;
602 break; 610 break;
603 case PARSE_EVENTS__TERM_TYPE_CONFIG2: 611 case PARSE_EVENTS__TERM_TYPE_CONFIG2:
612 CHECK_TYPE_VAL(NUM);
604 attr->config2 = term->val.num; 613 attr->config2 = term->val.num;
605 break; 614 break;
606 case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD: 615 case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
616 CHECK_TYPE_VAL(NUM);
607 attr->sample_period = term->val.num; 617 attr->sample_period = term->val.num;
608 break; 618 break;
609 case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE: 619 case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
@@ -615,7 +625,9 @@ static int config_term(struct perf_event_attr *attr,
615 default: 625 default:
616 return -EINVAL; 626 return -EINVAL;
617 } 627 }
628
618 return 0; 629 return 0;
630#undef CHECK_TYPE_VAL
619} 631}
620 632
621static int config_attr(struct perf_event_attr *attr, 633static int config_attr(struct perf_event_attr *attr,
@@ -1015,11 +1027,12 @@ void print_events(const char *event_glob)
1015 1027
1016int parse_events__is_hardcoded_term(struct parse_events__term *term) 1028int parse_events__is_hardcoded_term(struct parse_events__term *term)
1017{ 1029{
1018 return term->type <= PARSE_EVENTS__TERM_TYPE_HARDCODED_MAX; 1030 return term->type_term != PARSE_EVENTS__TERM_TYPE_USER;
1019} 1031}
1020 1032
1021int parse_events__new_term(struct parse_events__term **_term, int type, 1033static int new_term(struct parse_events__term **_term, int type_val,
1022 char *config, char *str, long num) 1034 int type_term, char *config,
1035 char *str, long num)
1023{ 1036{
1024 struct parse_events__term *term; 1037 struct parse_events__term *term;
1025 1038
@@ -1028,15 +1041,11 @@ int parse_events__new_term(struct parse_events__term **_term, int type,
1028 return -ENOMEM; 1041 return -ENOMEM;
1029 1042
1030 INIT_LIST_HEAD(&term->list); 1043 INIT_LIST_HEAD(&term->list);
1031 term->type = type; 1044 term->type_val = type_val;
1045 term->type_term = type_term;
1032 term->config = config; 1046 term->config = config;
1033 1047
1034 switch (type) { 1048 switch (type_val) {
1035 case PARSE_EVENTS__TERM_TYPE_CONFIG:
1036 case PARSE_EVENTS__TERM_TYPE_CONFIG1:
1037 case PARSE_EVENTS__TERM_TYPE_CONFIG2:
1038 case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
1039 case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
1040 case PARSE_EVENTS__TERM_TYPE_NUM: 1049 case PARSE_EVENTS__TERM_TYPE_NUM:
1041 term->val.num = num; 1050 term->val.num = num;
1042 break; 1051 break;
@@ -1051,6 +1060,20 @@ int parse_events__new_term(struct parse_events__term **_term, int type,
1051 return 0; 1060 return 0;
1052} 1061}
1053 1062
1063int parse_events__term_num(struct parse_events__term **term,
1064 int type_term, char *config, long num)
1065{
1066 return new_term(term, PARSE_EVENTS__TERM_TYPE_NUM, type_term,
1067 config, NULL, num);
1068}
1069
1070int parse_events__term_str(struct parse_events__term **term,
1071 int type_term, char *config, char *str)
1072{
1073 return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, type_term,
1074 config, str, 0);
1075}
1076
1054void parse_events__free_terms(struct list_head *terms) 1077void parse_events__free_terms(struct list_head *terms)
1055{ 1078{
1056 struct parse_events__term *term, *h; 1079 struct parse_events__term *term, *h;