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/perf/util/parse-events.c | |
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/perf/util/parse-events.c')
-rw-r--r-- | tools/perf/util/parse-events.c | 39 |
1 files changed, 24 insertions, 15 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); |