aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/util/parse-events.c39
-rw-r--r--tools/perf/util/parse-events.h16
-rw-r--r--tools/perf/util/parse-events.y69
3 files changed, 83 insertions, 41 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6704978736cc..4025e18765c4 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -26,8 +26,7 @@ struct event_symbol {
26#ifdef PARSER_DEBUG 26#ifdef PARSER_DEBUG
27extern int parse_events_debug; 27extern int parse_events_debug;
28#endif 28#endif
29int parse_events_parse(struct list_head *list, struct list_head *list_tmp, 29int parse_events_parse(struct list_head *list, int *idx);
30 int *idx);
31 30
32#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x 31#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
33#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x 32#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
@@ -358,20 +357,30 @@ const char *__event_name(int type, u64 config)
358 return "unknown"; 357 return "unknown";
359} 358}
360 359
361static int add_event(struct list_head *list, int *idx, 360static int add_event(struct list_head **_list, int *idx,
362 struct perf_event_attr *attr, char *name) 361 struct perf_event_attr *attr, char *name)
363{ 362{
364 struct perf_evsel *evsel; 363 struct perf_evsel *evsel;
364 struct list_head *list = *_list;
365
366 if (!list) {
367 list = malloc(sizeof(*list));
368 if (!list)
369 return -ENOMEM;
370 INIT_LIST_HEAD(list);
371 }
365 372
366 event_attr_init(attr); 373 event_attr_init(attr);
367 374
368 evsel = perf_evsel__new(attr, (*idx)++); 375 evsel = perf_evsel__new(attr, (*idx)++);
369 if (!evsel) 376 if (!evsel) {
377 free(list);
370 return -ENOMEM; 378 return -ENOMEM;
371 379 }
372 list_add_tail(&evsel->node, list);
373 380
374 evsel->name = strdup(name); 381 evsel->name = strdup(name);
382 list_add_tail(&evsel->node, list);
383 *_list = list;
375 return 0; 384 return 0;
376} 385}
377 386
@@ -393,7 +402,7 @@ static int parse_aliases(char *str, const char *names[][MAX_ALIASES], int size)
393 return -1; 402 return -1;
394} 403}
395 404
396int parse_events_add_cache(struct list_head *list, int *idx, 405int parse_events_add_cache(struct list_head **list, int *idx,
397 char *type, char *op_result1, char *op_result2) 406 char *type, char *op_result1, char *op_result2)
398{ 407{
399 struct perf_event_attr attr; 408 struct perf_event_attr attr;
@@ -454,7 +463,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
454 return add_event(list, idx, &attr, name); 463 return add_event(list, idx, &attr, name);
455} 464}
456 465
457static int add_tracepoint(struct list_head *list, int *idx, 466static int add_tracepoint(struct list_head **list, int *idx,
458 char *sys_name, char *evt_name) 467 char *sys_name, char *evt_name)
459{ 468{
460 struct perf_event_attr attr; 469 struct perf_event_attr attr;
@@ -491,7 +500,7 @@ static int add_tracepoint(struct list_head *list, int *idx,
491 return add_event(list, idx, &attr, name); 500 return add_event(list, idx, &attr, name);
492} 501}
493 502
494static int add_tracepoint_multi(struct list_head *list, int *idx, 503static int add_tracepoint_multi(struct list_head **list, int *idx,
495 char *sys_name, char *evt_name) 504 char *sys_name, char *evt_name)
496{ 505{
497 char evt_path[MAXPATHLEN]; 506 char evt_path[MAXPATHLEN];
@@ -522,7 +531,7 @@ static int add_tracepoint_multi(struct list_head *list, int *idx,
522 return ret; 531 return ret;
523} 532}
524 533
525int parse_events_add_tracepoint(struct list_head *list, int *idx, 534int parse_events_add_tracepoint(struct list_head **list, int *idx,
526 char *sys, char *event) 535 char *sys, char *event)
527{ 536{
528 int ret; 537 int ret;
@@ -566,7 +575,7 @@ parse_breakpoint_type(const char *type, struct perf_event_attr *attr)
566 return 0; 575 return 0;
567} 576}
568 577
569int parse_events_add_breakpoint(struct list_head *list, int *idx, 578int parse_events_add_breakpoint(struct list_head **list, int *idx,
570 void *ptr, char *type) 579 void *ptr, char *type)
571{ 580{
572 struct perf_event_attr attr; 581 struct perf_event_attr attr;
@@ -645,7 +654,7 @@ static int config_attr(struct perf_event_attr *attr,
645 return 0; 654 return 0;
646} 655}
647 656
648int parse_events_add_numeric(struct list_head *list, int *idx, 657int parse_events_add_numeric(struct list_head **list, int *idx,
649 unsigned long type, unsigned long config, 658 unsigned long type, unsigned long config,
650 struct list_head *head_config) 659 struct list_head *head_config)
651{ 660{
@@ -663,7 +672,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx,
663 (char *) __event_name(type, config)); 672 (char *) __event_name(type, config));
664} 673}
665 674
666int parse_events_add_pmu(struct list_head *list, int *idx, 675int parse_events_add_pmu(struct list_head **list, int *idx,
667 char *name, struct list_head *head_config) 676 char *name, struct list_head *head_config)
668{ 677{
669 struct perf_event_attr attr; 678 struct perf_event_attr attr;
@@ -696,7 +705,7 @@ void parse_events_update_lists(struct list_head *list_event,
696 * list, for next event definition. 705 * list, for next event definition.
697 */ 706 */
698 list_splice_tail(list_event, list_all); 707 list_splice_tail(list_event, list_all);
699 INIT_LIST_HEAD(list_event); 708 free(list_event);
700} 709}
701 710
702int parse_events_modifier(struct list_head *list, char *str) 711int parse_events_modifier(struct list_head *list, char *str)
@@ -774,7 +783,7 @@ int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
774#ifdef PARSER_DEBUG 783#ifdef PARSER_DEBUG
775 parse_events_debug = 1; 784 parse_events_debug = 1;
776#endif 785#endif
777 ret = parse_events_parse(&list, &list_tmp, &idx); 786 ret = parse_events_parse(&list, &idx);
778 787
779 parse_events__flush_buffer(buffer); 788 parse_events__flush_buffer(buffer);
780 parse_events__delete_buffer(buffer); 789 parse_events__delete_buffer(buffer);
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index d287adc2bb61..25ae3732f5b0 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -68,25 +68,21 @@ int parse_events__term_num(struct parse_events__term **_term,
68int parse_events__term_str(struct parse_events__term **_term, 68int parse_events__term_str(struct parse_events__term **_term,
69 int type_term, char *config, char *str); 69 int type_term, char *config, char *str);
70void parse_events__free_terms(struct list_head *terms); 70void parse_events__free_terms(struct list_head *terms);
71int parse_events_modifier(struct list_head *list __used, char *str __used); 71int parse_events_modifier(struct list_head *list, char *str);
72int parse_events_add_tracepoint(struct list_head *list, int *idx, 72int parse_events_add_tracepoint(struct list_head **list, int *idx,
73 char *sys, char *event); 73 char *sys, char *event);
74int parse_events_add_raw(struct perf_evlist *evlist, unsigned long config, 74int parse_events_add_numeric(struct list_head **list, int *idx,
75 unsigned long config1, unsigned long config2,
76 char *mod);
77int parse_events_add_numeric(struct list_head *list, int *idx,
78 unsigned long type, unsigned long config, 75 unsigned long type, unsigned long config,
79 struct list_head *head_config); 76 struct list_head *head_config);
80int parse_events_add_cache(struct list_head *list, int *idx, 77int parse_events_add_cache(struct list_head **list, int *idx,
81 char *type, char *op_result1, char *op_result2); 78 char *type, char *op_result1, char *op_result2);
82int parse_events_add_breakpoint(struct list_head *list, int *idx, 79int parse_events_add_breakpoint(struct list_head **list, int *idx,
83 void *ptr, char *type); 80 void *ptr, char *type);
84int parse_events_add_pmu(struct list_head *list, int *idx, 81int parse_events_add_pmu(struct list_head **list, int *idx,
85 char *pmu , struct list_head *head_config); 82 char *pmu , struct list_head *head_config);
86void parse_events_update_lists(struct list_head *list_event, 83void parse_events_update_lists(struct list_head *list_event,
87 struct list_head *list_all); 84 struct list_head *list_all);
88void parse_events_error(struct list_head *list_all, 85void parse_events_error(struct list_head *list_all,
89 struct list_head *list_event,
90 int *idx, char const *msg); 86 int *idx, char const *msg);
91int parse_events__test(void); 87int parse_events__test(void);
92 88
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 936913ea0ab6..126fad0a9936 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -1,7 +1,6 @@
1 1
2%name-prefix "parse_events_" 2%name-prefix "parse_events_"
3%parse-param {struct list_head *list_all} 3%parse-param {struct list_head *list_all}
4%parse-param {struct list_head *list_event}
5%parse-param {int *idx} 4%parse-param {int *idx}
6 5
7%{ 6%{
@@ -41,6 +40,14 @@ do { \
41%type <str> PE_MODIFIER_BP 40%type <str> PE_MODIFIER_BP
42%type <head> event_config 41%type <head> event_config
43%type <term> event_term 42%type <term> event_term
43%type <head> event_pmu
44%type <head> event_legacy_symbol
45%type <head> event_legacy_cache
46%type <head> event_legacy_mem
47%type <head> event_legacy_tracepoint
48%type <head> event_legacy_numeric
49%type <head> event_legacy_raw
50%type <head> event_def
44 51
45%union 52%union
46{ 53{
@@ -62,13 +69,13 @@ event_def PE_MODIFIER_EVENT
62 * (there could be more events added for multiple tracepoint 69 * (there could be more events added for multiple tracepoint
63 * definitions via '*?'. 70 * definitions via '*?'.
64 */ 71 */
65 ABORT_ON(parse_events_modifier(list_event, $2)); 72 ABORT_ON(parse_events_modifier($1, $2));
66 parse_events_update_lists(list_event, list_all); 73 parse_events_update_lists($1, list_all);
67} 74}
68| 75|
69event_def 76event_def
70{ 77{
71 parse_events_update_lists(list_event, list_all); 78 parse_events_update_lists($1, list_all);
72} 79}
73 80
74event_def: event_pmu | 81event_def: event_pmu |
@@ -82,71 +89,102 @@ event_def: event_pmu |
82event_pmu: 89event_pmu:
83PE_NAME '/' event_config '/' 90PE_NAME '/' event_config '/'
84{ 91{
85 ABORT_ON(parse_events_add_pmu(list_event, idx, $1, $3)); 92 struct list_head *list = NULL;
93
94 ABORT_ON(parse_events_add_pmu(&list, idx, $1, $3));
86 parse_events__free_terms($3); 95 parse_events__free_terms($3);
96 $$ = list;
87} 97}
88 98
89event_legacy_symbol: 99event_legacy_symbol:
90PE_VALUE_SYM '/' event_config '/' 100PE_VALUE_SYM '/' event_config '/'
91{ 101{
102 struct list_head *list = NULL;
92 int type = $1 >> 16; 103 int type = $1 >> 16;
93 int config = $1 & 255; 104 int config = $1 & 255;
94 105
95 ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, $3)); 106 ABORT_ON(parse_events_add_numeric(&list, idx, type, config, $3));
96 parse_events__free_terms($3); 107 parse_events__free_terms($3);
108 $$ = list;
97} 109}
98| 110|
99PE_VALUE_SYM sep_slash_dc 111PE_VALUE_SYM sep_slash_dc
100{ 112{
113 struct list_head *list = NULL;
101 int type = $1 >> 16; 114 int type = $1 >> 16;
102 int config = $1 & 255; 115 int config = $1 & 255;
103 116
104 ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, NULL)); 117 ABORT_ON(parse_events_add_numeric(&list, idx, type, config, NULL));
118 $$ = list;
105} 119}
106 120
107event_legacy_cache: 121event_legacy_cache:
108PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT 122PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
109{ 123{
110 ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, $5)); 124 struct list_head *list = NULL;
125
126 ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, $5));
127 $$ = list;
111} 128}
112| 129|
113PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT 130PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
114{ 131{
115 ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, NULL)); 132 struct list_head *list = NULL;
133
134 ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, NULL));
135 $$ = list;
116} 136}
117| 137|
118PE_NAME_CACHE_TYPE 138PE_NAME_CACHE_TYPE
119{ 139{
120 ABORT_ON(parse_events_add_cache(list_event, idx, $1, NULL, NULL)); 140 struct list_head *list = NULL;
141
142 ABORT_ON(parse_events_add_cache(&list, idx, $1, NULL, NULL));
143 $$ = list;
121} 144}
122 145
123event_legacy_mem: 146event_legacy_mem:
124PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc 147PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
125{ 148{
126 ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, $4)); 149 struct list_head *list = NULL;
150
151 ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, $4));
152 $$ = list;
127} 153}
128| 154|
129PE_PREFIX_MEM PE_VALUE sep_dc 155PE_PREFIX_MEM PE_VALUE sep_dc
130{ 156{
131 ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, NULL)); 157 struct list_head *list = NULL;
158
159 ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, NULL));
160 $$ = list;
132} 161}
133 162
134event_legacy_tracepoint: 163event_legacy_tracepoint:
135PE_NAME ':' PE_NAME 164PE_NAME ':' PE_NAME
136{ 165{
137 ABORT_ON(parse_events_add_tracepoint(list_event, idx, $1, $3)); 166 struct list_head *list = NULL;
167
168 ABORT_ON(parse_events_add_tracepoint(&list, idx, $1, $3));
169 $$ = list;
138} 170}
139 171
140event_legacy_numeric: 172event_legacy_numeric:
141PE_VALUE ':' PE_VALUE 173PE_VALUE ':' PE_VALUE
142{ 174{
143 ABORT_ON(parse_events_add_numeric(list_event, idx, $1, $3, NULL)); 175 struct list_head *list = NULL;
176
177 ABORT_ON(parse_events_add_numeric(&list, idx, $1, $3, NULL));
178 $$ = list;
144} 179}
145 180
146event_legacy_raw: 181event_legacy_raw:
147PE_RAW 182PE_RAW
148{ 183{
149 ABORT_ON(parse_events_add_numeric(list_event, idx, PERF_TYPE_RAW, $1, NULL)); 184 struct list_head *list = NULL;
185
186 ABORT_ON(parse_events_add_numeric(&list, idx, PERF_TYPE_RAW, $1, NULL));
187 $$ = list;
150} 188}
151 189
152event_config: 190event_config:
@@ -222,7 +260,6 @@ sep_slash_dc: '/' | ':' |
222%% 260%%
223 261
224void parse_events_error(struct list_head *list_all __used, 262void parse_events_error(struct list_head *list_all __used,
225 struct list_head *list_event __used,
226 int *idx __used, 263 int *idx __used,
227 char const *msg __used) 264 char const *msg __used)
228{ 265{