diff options
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r-- | tools/perf/util/parse-events.c | 74 |
1 files changed, 40 insertions, 34 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 649083f27e08..5cb6f4bde905 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -490,6 +490,31 @@ parse_multiple_tracepoint_event(char *sys_name, const char *evt_exp, | |||
490 | return EVT_HANDLED_ALL; | 490 | return EVT_HANDLED_ALL; |
491 | } | 491 | } |
492 | 492 | ||
493 | static int store_event_type(const char *orgname) | ||
494 | { | ||
495 | char filename[PATH_MAX], *c; | ||
496 | FILE *file; | ||
497 | int id, n; | ||
498 | |||
499 | sprintf(filename, "%s/", debugfs_path); | ||
500 | strncat(filename, orgname, strlen(orgname)); | ||
501 | strcat(filename, "/id"); | ||
502 | |||
503 | c = strchr(filename, ':'); | ||
504 | if (c) | ||
505 | *c = '/'; | ||
506 | |||
507 | file = fopen(filename, "r"); | ||
508 | if (!file) | ||
509 | return 0; | ||
510 | n = fscanf(file, "%i", &id); | ||
511 | fclose(file); | ||
512 | if (n < 1) { | ||
513 | pr_err("cannot store event ID\n"); | ||
514 | return -EINVAL; | ||
515 | } | ||
516 | return perf_header__push_event(id, orgname); | ||
517 | } | ||
493 | 518 | ||
494 | static enum event_result parse_tracepoint_event(const char **strp, | 519 | static enum event_result parse_tracepoint_event(const char **strp, |
495 | struct perf_event_attr *attr) | 520 | struct perf_event_attr *attr) |
@@ -533,9 +558,13 @@ static enum event_result parse_tracepoint_event(const char **strp, | |||
533 | *strp += strlen(sys_name) + evt_length; | 558 | *strp += strlen(sys_name) + evt_length; |
534 | return parse_multiple_tracepoint_event(sys_name, evt_name, | 559 | return parse_multiple_tracepoint_event(sys_name, evt_name, |
535 | flags); | 560 | flags); |
536 | } else | 561 | } else { |
562 | if (store_event_type(evt_name) < 0) | ||
563 | return EVT_FAILED; | ||
564 | |||
537 | return parse_single_tracepoint_event(sys_name, evt_name, | 565 | return parse_single_tracepoint_event(sys_name, evt_name, |
538 | evt_length, attr, strp); | 566 | evt_length, attr, strp); |
567 | } | ||
539 | } | 568 | } |
540 | 569 | ||
541 | static enum event_result | 570 | static enum event_result |
@@ -778,41 +807,11 @@ modifier: | |||
778 | return ret; | 807 | return ret; |
779 | } | 808 | } |
780 | 809 | ||
781 | static int store_event_type(const char *orgname) | ||
782 | { | ||
783 | char filename[PATH_MAX], *c; | ||
784 | FILE *file; | ||
785 | int id, n; | ||
786 | |||
787 | sprintf(filename, "%s/", debugfs_path); | ||
788 | strncat(filename, orgname, strlen(orgname)); | ||
789 | strcat(filename, "/id"); | ||
790 | |||
791 | c = strchr(filename, ':'); | ||
792 | if (c) | ||
793 | *c = '/'; | ||
794 | |||
795 | file = fopen(filename, "r"); | ||
796 | if (!file) | ||
797 | return 0; | ||
798 | n = fscanf(file, "%i", &id); | ||
799 | fclose(file); | ||
800 | if (n < 1) { | ||
801 | pr_err("cannot store event ID\n"); | ||
802 | return -EINVAL; | ||
803 | } | ||
804 | return perf_header__push_event(id, orgname); | ||
805 | } | ||
806 | |||
807 | int parse_events(const struct option *opt __used, const char *str, int unset __used) | 810 | int parse_events(const struct option *opt __used, const char *str, int unset __used) |
808 | { | 811 | { |
809 | struct perf_event_attr attr; | 812 | struct perf_event_attr attr; |
810 | enum event_result ret; | 813 | enum event_result ret; |
811 | 814 | ||
812 | if (strchr(str, ':')) | ||
813 | if (store_event_type(str) < 0) | ||
814 | return -1; | ||
815 | |||
816 | for (;;) { | 815 | for (;;) { |
817 | memset(&attr, 0, sizeof(attr)); | 816 | memset(&attr, 0, sizeof(attr)); |
818 | ret = parse_event_symbols(&str, &attr); | 817 | ret = parse_event_symbols(&str, &attr); |
@@ -824,7 +823,7 @@ int parse_events(const struct option *opt __used, const char *str, int unset __u | |||
824 | 823 | ||
825 | if (ret != EVT_HANDLED_ALL) { | 824 | if (ret != EVT_HANDLED_ALL) { |
826 | struct perf_evsel *evsel; | 825 | struct perf_evsel *evsel; |
827 | evsel = perf_evsel__new(attr.type, attr.config, | 826 | evsel = perf_evsel__new(&attr, |
828 | nr_counters); | 827 | nr_counters); |
829 | if (evsel == NULL) | 828 | if (evsel == NULL) |
830 | return -1; | 829 | return -1; |
@@ -1014,8 +1013,15 @@ void print_events(void) | |||
1014 | 1013 | ||
1015 | int perf_evsel_list__create_default(void) | 1014 | int perf_evsel_list__create_default(void) |
1016 | { | 1015 | { |
1017 | struct perf_evsel *evsel = perf_evsel__new(PERF_TYPE_HARDWARE, | 1016 | struct perf_evsel *evsel; |
1018 | PERF_COUNT_HW_CPU_CYCLES, 0); | 1017 | struct perf_event_attr attr; |
1018 | |||
1019 | memset(&attr, 0, sizeof(attr)); | ||
1020 | attr.type = PERF_TYPE_HARDWARE; | ||
1021 | attr.config = PERF_COUNT_HW_CPU_CYCLES; | ||
1022 | |||
1023 | evsel = perf_evsel__new(&attr, 0); | ||
1024 | |||
1019 | if (evsel == NULL) | 1025 | if (evsel == NULL) |
1020 | return -ENOMEM; | 1026 | return -ENOMEM; |
1021 | 1027 | ||