diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-05-21 03:12:51 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-22 10:22:28 -0400 |
commit | b847cbdc6750bdea248ace75c1868f8ef57dcdf0 (patch) | |
tree | b42f8fa93f093f2a3a23f13274f8e7cddcc6123b /tools | |
parent | 82ba1f2f614871b388cb1bd58594507b6f0f2b79 (diff) |
perf tools: Use allocated list for each parsed event
Switch from using static temporary event list into dynamically allocated
one. This way we dont need to pass temp list to the parse_events_parse
which makes the interface more clear.
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-4-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.c | 39 | ||||
-rw-r--r-- | tools/perf/util/parse-events.h | 16 | ||||
-rw-r--r-- | tools/perf/util/parse-events.y | 69 |
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 |
27 | extern int parse_events_debug; | 27 | extern int parse_events_debug; |
28 | #endif | 28 | #endif |
29 | int parse_events_parse(struct list_head *list, struct list_head *list_tmp, | 29 | int 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 | ||
361 | static int add_event(struct list_head *list, int *idx, | 360 | static 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 | ||
396 | int parse_events_add_cache(struct list_head *list, int *idx, | 405 | int 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 | ||
457 | static int add_tracepoint(struct list_head *list, int *idx, | 466 | static 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 | ||
494 | static int add_tracepoint_multi(struct list_head *list, int *idx, | 503 | static 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 | ||
525 | int parse_events_add_tracepoint(struct list_head *list, int *idx, | 534 | int 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 | ||
569 | int parse_events_add_breakpoint(struct list_head *list, int *idx, | 578 | int 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 | ||
648 | int parse_events_add_numeric(struct list_head *list, int *idx, | 657 | int 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 | ||
666 | int parse_events_add_pmu(struct list_head *list, int *idx, | 675 | int 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 | ||
702 | int parse_events_modifier(struct list_head *list, char *str) | 711 | int 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, | |||
68 | int parse_events__term_str(struct parse_events__term **_term, | 68 | int 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); |
70 | void parse_events__free_terms(struct list_head *terms); | 70 | void parse_events__free_terms(struct list_head *terms); |
71 | int parse_events_modifier(struct list_head *list __used, char *str __used); | 71 | int parse_events_modifier(struct list_head *list, char *str); |
72 | int parse_events_add_tracepoint(struct list_head *list, int *idx, | 72 | int parse_events_add_tracepoint(struct list_head **list, int *idx, |
73 | char *sys, char *event); | 73 | char *sys, char *event); |
74 | int parse_events_add_raw(struct perf_evlist *evlist, unsigned long config, | 74 | int parse_events_add_numeric(struct list_head **list, int *idx, |
75 | unsigned long config1, unsigned long config2, | ||
76 | char *mod); | ||
77 | int 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); |
80 | int parse_events_add_cache(struct list_head *list, int *idx, | 77 | int 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); |
82 | int parse_events_add_breakpoint(struct list_head *list, int *idx, | 79 | int parse_events_add_breakpoint(struct list_head **list, int *idx, |
83 | void *ptr, char *type); | 80 | void *ptr, char *type); |
84 | int parse_events_add_pmu(struct list_head *list, int *idx, | 81 | int 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); |
86 | void parse_events_update_lists(struct list_head *list_event, | 83 | void parse_events_update_lists(struct list_head *list_event, |
87 | struct list_head *list_all); | 84 | struct list_head *list_all); |
88 | void parse_events_error(struct list_head *list_all, | 85 | void 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); |
91 | int parse_events__test(void); | 87 | int 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 | | |
69 | event_def | 76 | event_def |
70 | { | 77 | { |
71 | parse_events_update_lists(list_event, list_all); | 78 | parse_events_update_lists($1, list_all); |
72 | } | 79 | } |
73 | 80 | ||
74 | event_def: event_pmu | | 81 | event_def: event_pmu | |
@@ -82,71 +89,102 @@ event_def: event_pmu | | |||
82 | event_pmu: | 89 | event_pmu: |
83 | PE_NAME '/' event_config '/' | 90 | PE_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 | ||
89 | event_legacy_symbol: | 99 | event_legacy_symbol: |
90 | PE_VALUE_SYM '/' event_config '/' | 100 | PE_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 | | |
99 | PE_VALUE_SYM sep_slash_dc | 111 | PE_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 | ||
107 | event_legacy_cache: | 121 | event_legacy_cache: |
108 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT | 122 | PE_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 | | |
113 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT | 130 | PE_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 | | |
118 | PE_NAME_CACHE_TYPE | 138 | PE_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 | ||
123 | event_legacy_mem: | 146 | event_legacy_mem: |
124 | PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc | 147 | PE_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 | | |
129 | PE_PREFIX_MEM PE_VALUE sep_dc | 155 | PE_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 | ||
134 | event_legacy_tracepoint: | 163 | event_legacy_tracepoint: |
135 | PE_NAME ':' PE_NAME | 164 | PE_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 | ||
140 | event_legacy_numeric: | 172 | event_legacy_numeric: |
141 | PE_VALUE ':' PE_VALUE | 173 | PE_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 | ||
146 | event_legacy_raw: | 181 | event_legacy_raw: |
147 | PE_RAW | 182 | PE_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 | ||
152 | event_config: | 190 | event_config: |
@@ -222,7 +260,6 @@ sep_slash_dc: '/' | ':' | | |||
222 | %% | 260 | %% |
223 | 261 | ||
224 | void parse_events_error(struct list_head *list_all __used, | 262 | void 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 | { |