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.c43
1 files changed, 20 insertions, 23 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index b097570e9623..0faf4f2bb5ca 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -7,6 +7,7 @@
7#include "string.h" 7#include "string.h"
8#include "cache.h" 8#include "cache.h"
9#include "header.h" 9#include "header.h"
10#include "debugfs.h"
10 11
11int nr_counters; 12int nr_counters;
12 13
@@ -47,6 +48,8 @@ static struct event_symbol event_symbols[] = {
47 { CSW(PAGE_FAULTS_MAJ), "major-faults", "" }, 48 { CSW(PAGE_FAULTS_MAJ), "major-faults", "" },
48 { CSW(CONTEXT_SWITCHES), "context-switches", "cs" }, 49 { CSW(CONTEXT_SWITCHES), "context-switches", "cs" },
49 { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" }, 50 { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" },
51 { CSW(ALIGNMENT_FAULTS), "alignment-faults", "" },
52 { CSW(EMULATION_FAULTS), "emulation-faults", "" },
50}; 53};
51 54
52#define __PERF_EVENT_FIELD(config, name) \ 55#define __PERF_EVENT_FIELD(config, name) \
@@ -75,6 +78,8 @@ static const char *sw_event_names[] = {
75 "CPU-migrations", 78 "CPU-migrations",
76 "minor-faults", 79 "minor-faults",
77 "major-faults", 80 "major-faults",
81 "alignment-faults",
82 "emulation-faults",
78}; 83};
79 84
80#define MAX_ALIASES 8 85#define MAX_ALIASES 8
@@ -149,16 +154,6 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
149 154
150#define MAX_EVENT_LENGTH 512 155#define MAX_EVENT_LENGTH 512
151 156
152int valid_debugfs_mount(const char *debugfs)
153{
154 struct statfs st_fs;
155
156 if (statfs(debugfs, &st_fs) < 0)
157 return -ENOENT;
158 else if (st_fs.f_type != (long) DEBUGFS_MAGIC)
159 return -ENOENT;
160 return 0;
161}
162 157
163struct tracepoint_path *tracepoint_id_to_path(u64 config) 158struct tracepoint_path *tracepoint_id_to_path(u64 config)
164{ 159{
@@ -171,7 +166,7 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
171 char evt_path[MAXPATHLEN]; 166 char evt_path[MAXPATHLEN];
172 char dir_path[MAXPATHLEN]; 167 char dir_path[MAXPATHLEN];
173 168
174 if (valid_debugfs_mount(debugfs_path)) 169 if (debugfs_valid_mountpoint(debugfs_path))
175 return NULL; 170 return NULL;
176 171
177 sys_dir = opendir(debugfs_path); 172 sys_dir = opendir(debugfs_path);
@@ -510,7 +505,7 @@ static enum event_result parse_tracepoint_event(const char **strp,
510 char sys_name[MAX_EVENT_LENGTH]; 505 char sys_name[MAX_EVENT_LENGTH];
511 unsigned int sys_length, evt_length; 506 unsigned int sys_length, evt_length;
512 507
513 if (valid_debugfs_mount(debugfs_path)) 508 if (debugfs_valid_mountpoint(debugfs_path))
514 return 0; 509 return 0;
515 510
516 evt_name = strchr(*strp, ':'); 511 evt_name = strchr(*strp, ':');
@@ -678,6 +673,8 @@ parse_event_symbols(const char **str, struct perf_event_attr *attr)
678 if (ret != EVT_FAILED) 673 if (ret != EVT_FAILED)
679 goto modifier; 674 goto modifier;
680 675
676 fprintf(stderr, "invalid or unsupported event: '%s'\n", *str);
677 fprintf(stderr, "Run 'perf list' for a list of valid events\n");
681 return EVT_FAILED; 678 return EVT_FAILED;
682 679
683modifier: 680modifier:
@@ -786,7 +783,7 @@ static void print_tracepoint_events(void)
786 char evt_path[MAXPATHLEN]; 783 char evt_path[MAXPATHLEN];
787 char dir_path[MAXPATHLEN]; 784 char dir_path[MAXPATHLEN];
788 785
789 if (valid_debugfs_mount(debugfs_path)) 786 if (debugfs_valid_mountpoint(debugfs_path))
790 return; 787 return;
791 788
792 sys_dir = opendir(debugfs_path); 789 sys_dir = opendir(debugfs_path);
@@ -804,7 +801,7 @@ static void print_tracepoint_events(void)
804 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { 801 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
805 snprintf(evt_path, MAXPATHLEN, "%s:%s", 802 snprintf(evt_path, MAXPATHLEN, "%s:%s",
806 sys_dirent.d_name, evt_dirent.d_name); 803 sys_dirent.d_name, evt_dirent.d_name);
807 fprintf(stderr, " %-42s [%s]\n", evt_path, 804 printf(" %-42s [%s]\n", evt_path,
808 event_type_descriptors[PERF_TYPE_TRACEPOINT+1]); 805 event_type_descriptors[PERF_TYPE_TRACEPOINT+1]);
809 } 806 }
810 closedir(evt_dir); 807 closedir(evt_dir);
@@ -821,8 +818,8 @@ void print_events(void)
821 unsigned int i, type, op, prev_type = -1; 818 unsigned int i, type, op, prev_type = -1;
822 char name[40]; 819 char name[40];
823 820
824 fprintf(stderr, "\n"); 821 printf("\n");
825 fprintf(stderr, "List of pre-defined events (to be used in -e):\n"); 822 printf("List of pre-defined events (to be used in -e):\n");
826 823
827 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { 824 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
828 type = syms->type + 1; 825 type = syms->type + 1;
@@ -830,19 +827,19 @@ void print_events(void)
830 type = 0; 827 type = 0;
831 828
832 if (type != prev_type) 829 if (type != prev_type)
833 fprintf(stderr, "\n"); 830 printf("\n");
834 831
835 if (strlen(syms->alias)) 832 if (strlen(syms->alias))
836 sprintf(name, "%s OR %s", syms->symbol, syms->alias); 833 sprintf(name, "%s OR %s", syms->symbol, syms->alias);
837 else 834 else
838 strcpy(name, syms->symbol); 835 strcpy(name, syms->symbol);
839 fprintf(stderr, " %-42s [%s]\n", name, 836 printf(" %-42s [%s]\n", name,
840 event_type_descriptors[type]); 837 event_type_descriptors[type]);
841 838
842 prev_type = type; 839 prev_type = type;
843 } 840 }
844 841
845 fprintf(stderr, "\n"); 842 printf("\n");
846 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { 843 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
847 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { 844 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
848 /* skip invalid cache type */ 845 /* skip invalid cache type */
@@ -850,17 +847,17 @@ void print_events(void)
850 continue; 847 continue;
851 848
852 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { 849 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
853 fprintf(stderr, " %-42s [%s]\n", 850 printf(" %-42s [%s]\n",
854 event_cache_name(type, op, i), 851 event_cache_name(type, op, i),
855 event_type_descriptors[4]); 852 event_type_descriptors[4]);
856 } 853 }
857 } 854 }
858 } 855 }
859 856
860 fprintf(stderr, "\n"); 857 printf("\n");
861 fprintf(stderr, " %-42s [raw hardware event descriptor]\n", 858 printf(" %-42s [raw hardware event descriptor]\n",
862 "rNNN"); 859 "rNNN");
863 fprintf(stderr, "\n"); 860 printf("\n");
864 861
865 print_tracepoint_events(); 862 print_tracepoint_events();
866 863