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.c104
1 files changed, 86 insertions, 18 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index cf082daa43e3..54a7e2634d58 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -268,6 +268,9 @@ const char *event_name(struct perf_evsel *evsel)
268 u64 config = evsel->attr.config; 268 u64 config = evsel->attr.config;
269 int type = evsel->attr.type; 269 int type = evsel->attr.type;
270 270
271 if (evsel->name)
272 return evsel->name;
273
271 return __event_name(type, config); 274 return __event_name(type, config);
272} 275}
273 276
@@ -782,8 +785,10 @@ int parse_events(const struct option *opt, const char *str, int unset __used)
782 struct perf_evlist *evlist = *(struct perf_evlist **)opt->value; 785 struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
783 struct perf_event_attr attr; 786 struct perf_event_attr attr;
784 enum event_result ret; 787 enum event_result ret;
788 const char *ostr;
785 789
786 for (;;) { 790 for (;;) {
791 ostr = str;
787 memset(&attr, 0, sizeof(attr)); 792 memset(&attr, 0, sizeof(attr));
788 ret = parse_event_symbols(opt, &str, &attr); 793 ret = parse_event_symbols(opt, &str, &attr);
789 if (ret == EVT_FAILED) 794 if (ret == EVT_FAILED)
@@ -798,6 +803,11 @@ int parse_events(const struct option *opt, const char *str, int unset __used)
798 if (evsel == NULL) 803 if (evsel == NULL)
799 return -1; 804 return -1;
800 perf_evlist__add(evlist, evsel); 805 perf_evlist__add(evlist, evsel);
806
807 evsel->name = calloc(str - ostr + 1, 1);
808 if (!evsel->name)
809 return -1;
810 strncpy(evsel->name, ostr, str - ostr);
801 } 811 }
802 812
803 if (*str == 0) 813 if (*str == 0)
@@ -848,7 +858,7 @@ static const char * const event_type_descriptors[] = {
848 * Print the events from <debugfs_mount_point>/tracing/events 858 * Print the events from <debugfs_mount_point>/tracing/events
849 */ 859 */
850 860
851static void print_tracepoint_events(void) 861void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
852{ 862{
853 DIR *sys_dir, *evt_dir; 863 DIR *sys_dir, *evt_dir;
854 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 864 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
@@ -863,6 +873,9 @@ static void print_tracepoint_events(void)
863 return; 873 return;
864 874
865 for_each_subsystem(sys_dir, sys_dirent, sys_next) { 875 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
876 if (subsys_glob != NULL &&
877 !strglobmatch(sys_dirent.d_name, subsys_glob))
878 continue;
866 879
867 snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, 880 snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
868 sys_dirent.d_name); 881 sys_dirent.d_name);
@@ -871,6 +884,10 @@ static void print_tracepoint_events(void)
871 continue; 884 continue;
872 885
873 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { 886 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
887 if (event_glob != NULL &&
888 !strglobmatch(evt_dirent.d_name, event_glob))
889 continue;
890
874 snprintf(evt_path, MAXPATHLEN, "%s:%s", 891 snprintf(evt_path, MAXPATHLEN, "%s:%s",
875 sys_dirent.d_name, evt_dirent.d_name); 892 sys_dirent.d_name, evt_dirent.d_name);
876 printf(" %-42s [%s]\n", evt_path, 893 printf(" %-42s [%s]\n", evt_path,
@@ -922,13 +939,61 @@ int is_valid_tracepoint(const char *event_string)
922 return 0; 939 return 0;
923} 940}
924 941
942void print_events_type(u8 type)
943{
944 struct event_symbol *syms = event_symbols;
945 unsigned int i;
946 char name[64];
947
948 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
949 if (type != syms->type)
950 continue;
951
952 if (strlen(syms->alias))
953 snprintf(name, sizeof(name), "%s OR %s",
954 syms->symbol, syms->alias);
955 else
956 snprintf(name, sizeof(name), "%s", syms->symbol);
957
958 printf(" %-42s [%s]\n", name,
959 event_type_descriptors[type]);
960 }
961}
962
963int print_hwcache_events(const char *event_glob)
964{
965 unsigned int type, op, i, printed = 0;
966
967 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
968 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
969 /* skip invalid cache type */
970 if (!is_cache_op_valid(type, op))
971 continue;
972
973 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
974 char *name = event_cache_name(type, op, i);
975
976 if (event_glob != NULL &&
977 !strglobmatch(name, event_glob))
978 continue;
979
980 printf(" %-42s [%s]\n", name,
981 event_type_descriptors[PERF_TYPE_HW_CACHE]);
982 ++printed;
983 }
984 }
985 }
986
987 return printed;
988}
989
925/* 990/*
926 * Print the help text for the event symbols: 991 * Print the help text for the event symbols:
927 */ 992 */
928void print_events(void) 993void print_events(const char *event_glob)
929{ 994{
930 struct event_symbol *syms = event_symbols; 995 struct event_symbol *syms = event_symbols;
931 unsigned int i, type, op, prev_type = -1; 996 unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0;
932 char name[40]; 997 char name[40];
933 998
934 printf("\n"); 999 printf("\n");
@@ -937,8 +1002,16 @@ void print_events(void)
937 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { 1002 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
938 type = syms->type; 1003 type = syms->type;
939 1004
940 if (type != prev_type) 1005 if (type != prev_type && printed) {
941 printf("\n"); 1006 printf("\n");
1007 printed = 0;
1008 ntypes_printed++;
1009 }
1010
1011 if (event_glob != NULL &&
1012 !(strglobmatch(syms->symbol, event_glob) ||
1013 (syms->alias && strglobmatch(syms->alias, event_glob))))
1014 continue;
942 1015
943 if (strlen(syms->alias)) 1016 if (strlen(syms->alias))
944 sprintf(name, "%s OR %s", syms->symbol, syms->alias); 1017 sprintf(name, "%s OR %s", syms->symbol, syms->alias);
@@ -948,22 +1021,17 @@ void print_events(void)
948 event_type_descriptors[type]); 1021 event_type_descriptors[type]);
949 1022
950 prev_type = type; 1023 prev_type = type;
1024 ++printed;
951 } 1025 }
952 1026
953 printf("\n"); 1027 if (ntypes_printed) {
954 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { 1028 printed = 0;
955 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { 1029 printf("\n");
956 /* skip invalid cache type */
957 if (!is_cache_op_valid(type, op))
958 continue;
959
960 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
961 printf(" %-42s [%s]\n",
962 event_cache_name(type, op, i),
963 event_type_descriptors[PERF_TYPE_HW_CACHE]);
964 }
965 }
966 } 1030 }
1031 print_hwcache_events(event_glob);
1032
1033 if (event_glob != NULL)
1034 return;
967 1035
968 printf("\n"); 1036 printf("\n");
969 printf(" %-42s [%s]\n", 1037 printf(" %-42s [%s]\n",
@@ -976,7 +1044,7 @@ void print_events(void)
976 event_type_descriptors[PERF_TYPE_BREAKPOINT]); 1044 event_type_descriptors[PERF_TYPE_BREAKPOINT]);
977 printf("\n"); 1045 printf("\n");
978 1046
979 print_tracepoint_events(); 1047 print_tracepoint_events(NULL, NULL);
980 1048
981 exit(129); 1049 exit(129);
982} 1050}