diff options
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r-- | tools/perf/util/parse-events.c | 182 |
1 files changed, 178 insertions, 4 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5184959e0615..7bdad8df22a6 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "parse-events.h" | 5 | #include "parse-events.h" |
6 | #include "exec_cmd.h" | 6 | #include "exec_cmd.h" |
7 | #include "string.h" | 7 | #include "string.h" |
8 | #include "cache.h" | ||
8 | 9 | ||
9 | extern char *strcasestr(const char *haystack, const char *needle); | 10 | extern char *strcasestr(const char *haystack, const char *needle); |
10 | 11 | ||
@@ -19,6 +20,8 @@ struct event_symbol { | |||
19 | char *alias; | 20 | char *alias; |
20 | }; | 21 | }; |
21 | 22 | ||
23 | char debugfs_path[MAXPATHLEN]; | ||
24 | |||
22 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x | 25 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x |
23 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x | 26 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x |
24 | 27 | ||
@@ -71,8 +74,8 @@ static char *sw_event_names[] = { | |||
71 | #define MAX_ALIASES 8 | 74 | #define MAX_ALIASES 8 |
72 | 75 | ||
73 | static char *hw_cache[][MAX_ALIASES] = { | 76 | static char *hw_cache[][MAX_ALIASES] = { |
74 | { "L1-d$", "l1-d", "l1d", "L1-data", }, | 77 | { "L1-dcache", "l1-d", "l1d", "L1-data", }, |
75 | { "L1-i$", "l1-i", "l1i", "L1-instruction", }, | 78 | { "L1-icache", "l1-i", "l1i", "L1-instruction", }, |
76 | { "LLC", "L2" }, | 79 | { "LLC", "L2" }, |
77 | { "dTLB", "d-tlb", "Data-TLB", }, | 80 | { "dTLB", "d-tlb", "Data-TLB", }, |
78 | { "iTLB", "i-tlb", "Instruction-TLB", }, | 81 | { "iTLB", "i-tlb", "Instruction-TLB", }, |
@@ -110,6 +113,88 @@ static unsigned long hw_cache_stat[C(MAX)] = { | |||
110 | [C(BPU)] = (CACHE_READ), | 113 | [C(BPU)] = (CACHE_READ), |
111 | }; | 114 | }; |
112 | 115 | ||
116 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next, file, st) \ | ||
117 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ | ||
118 | if (snprintf(file, MAXPATHLEN, "%s/%s", debugfs_path, \ | ||
119 | sys_dirent.d_name) && \ | ||
120 | (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \ | ||
121 | (strcmp(sys_dirent.d_name, ".")) && \ | ||
122 | (strcmp(sys_dirent.d_name, ".."))) | ||
123 | |||
124 | #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next, file, st) \ | ||
125 | while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ | ||
126 | if (snprintf(file, MAXPATHLEN, "%s/%s/%s", debugfs_path, \ | ||
127 | sys_dirent.d_name, evt_dirent.d_name) && \ | ||
128 | (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \ | ||
129 | (strcmp(evt_dirent.d_name, ".")) && \ | ||
130 | (strcmp(evt_dirent.d_name, ".."))) | ||
131 | |||
132 | #define MAX_EVENT_LENGTH 30 | ||
133 | |||
134 | int valid_debugfs_mount(const char *debugfs) | ||
135 | { | ||
136 | struct statfs st_fs; | ||
137 | |||
138 | if (statfs(debugfs, &st_fs) < 0) | ||
139 | return -ENOENT; | ||
140 | else if (st_fs.f_type != (long) DEBUGFS_MAGIC) | ||
141 | return -ENOENT; | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | static char *tracepoint_id_to_name(u64 config) | ||
146 | { | ||
147 | static char tracepoint_name[2 * MAX_EVENT_LENGTH]; | ||
148 | DIR *sys_dir, *evt_dir; | ||
149 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | ||
150 | struct stat st; | ||
151 | char id_buf[4]; | ||
152 | int fd; | ||
153 | u64 id; | ||
154 | char evt_path[MAXPATHLEN]; | ||
155 | |||
156 | if (valid_debugfs_mount(debugfs_path)) | ||
157 | return "unkown"; | ||
158 | |||
159 | sys_dir = opendir(debugfs_path); | ||
160 | if (!sys_dir) | ||
161 | goto cleanup; | ||
162 | |||
163 | for_each_subsystem(sys_dir, sys_dirent, sys_next, evt_path, st) { | ||
164 | evt_dir = opendir(evt_path); | ||
165 | if (!evt_dir) | ||
166 | goto cleanup; | ||
167 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next, | ||
168 | evt_path, st) { | ||
169 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", | ||
170 | debugfs_path, sys_dirent.d_name, | ||
171 | evt_dirent.d_name); | ||
172 | fd = open(evt_path, O_RDONLY); | ||
173 | if (fd < 0) | ||
174 | continue; | ||
175 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | ||
176 | close(fd); | ||
177 | continue; | ||
178 | } | ||
179 | close(fd); | ||
180 | id = atoll(id_buf); | ||
181 | if (id == config) { | ||
182 | closedir(evt_dir); | ||
183 | closedir(sys_dir); | ||
184 | snprintf(tracepoint_name, 2 * MAX_EVENT_LENGTH, | ||
185 | "%s:%s", sys_dirent.d_name, | ||
186 | evt_dirent.d_name); | ||
187 | return tracepoint_name; | ||
188 | } | ||
189 | } | ||
190 | closedir(evt_dir); | ||
191 | } | ||
192 | |||
193 | cleanup: | ||
194 | closedir(sys_dir); | ||
195 | return "unkown"; | ||
196 | } | ||
197 | |||
113 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) | 198 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) |
114 | { | 199 | { |
115 | if (hw_cache_stat[cache_type] & COP(cache_op)) | 200 | if (hw_cache_stat[cache_type] & COP(cache_op)) |
@@ -177,6 +262,9 @@ char *event_name(int counter) | |||
177 | return sw_event_names[config]; | 262 | return sw_event_names[config]; |
178 | return "unknown-software"; | 263 | return "unknown-software"; |
179 | 264 | ||
265 | case PERF_TYPE_TRACEPOINT: | ||
266 | return tracepoint_id_to_name(config); | ||
267 | |||
180 | default: | 268 | default: |
181 | break; | 269 | break; |
182 | } | 270 | } |
@@ -265,6 +353,53 @@ parse_generic_hw_event(const char **str, struct perf_counter_attr *attr) | |||
265 | return 1; | 353 | return 1; |
266 | } | 354 | } |
267 | 355 | ||
356 | static int parse_tracepoint_event(const char **strp, | ||
357 | struct perf_counter_attr *attr) | ||
358 | { | ||
359 | const char *evt_name; | ||
360 | char sys_name[MAX_EVENT_LENGTH]; | ||
361 | char id_buf[4]; | ||
362 | int fd; | ||
363 | unsigned int sys_length, evt_length; | ||
364 | u64 id; | ||
365 | char evt_path[MAXPATHLEN]; | ||
366 | |||
367 | if (valid_debugfs_mount(debugfs_path)) | ||
368 | return 0; | ||
369 | |||
370 | evt_name = strchr(*strp, ':'); | ||
371 | if (!evt_name) | ||
372 | return 0; | ||
373 | |||
374 | sys_length = evt_name - *strp; | ||
375 | if (sys_length >= MAX_EVENT_LENGTH) | ||
376 | return 0; | ||
377 | |||
378 | strncpy(sys_name, *strp, sys_length); | ||
379 | sys_name[sys_length] = '\0'; | ||
380 | evt_name = evt_name + 1; | ||
381 | evt_length = strlen(evt_name); | ||
382 | if (evt_length >= MAX_EVENT_LENGTH) | ||
383 | return 0; | ||
384 | |||
385 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, | ||
386 | sys_name, evt_name); | ||
387 | fd = open(evt_path, O_RDONLY); | ||
388 | if (fd < 0) | ||
389 | return 0; | ||
390 | |||
391 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | ||
392 | close(fd); | ||
393 | return 0; | ||
394 | } | ||
395 | close(fd); | ||
396 | id = atoll(id_buf); | ||
397 | attr->config = id; | ||
398 | attr->type = PERF_TYPE_TRACEPOINT; | ||
399 | *strp = evt_name + evt_length; | ||
400 | return 1; | ||
401 | } | ||
402 | |||
268 | static int check_events(const char *str, unsigned int i) | 403 | static int check_events(const char *str, unsigned int i) |
269 | { | 404 | { |
270 | int n; | 405 | int n; |
@@ -374,7 +509,8 @@ parse_event_modifier(const char **strp, struct perf_counter_attr *attr) | |||
374 | */ | 509 | */ |
375 | static int parse_event_symbols(const char **str, struct perf_counter_attr *attr) | 510 | static int parse_event_symbols(const char **str, struct perf_counter_attr *attr) |
376 | { | 511 | { |
377 | if (!(parse_raw_event(str, attr) || | 512 | if (!(parse_tracepoint_event(str, attr) || |
513 | parse_raw_event(str, attr) || | ||
378 | parse_numeric_event(str, attr) || | 514 | parse_numeric_event(str, attr) || |
379 | parse_symbolic_event(str, attr) || | 515 | parse_symbolic_event(str, attr) || |
380 | parse_generic_hw_event(str, attr))) | 516 | parse_generic_hw_event(str, attr))) |
@@ -423,6 +559,42 @@ static const char * const event_type_descriptors[] = { | |||
423 | }; | 559 | }; |
424 | 560 | ||
425 | /* | 561 | /* |
562 | * Print the events from <debugfs_mount_point>/tracing/events | ||
563 | */ | ||
564 | |||
565 | static void print_tracepoint_events(void) | ||
566 | { | ||
567 | DIR *sys_dir, *evt_dir; | ||
568 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | ||
569 | struct stat st; | ||
570 | char evt_path[MAXPATHLEN]; | ||
571 | |||
572 | if (valid_debugfs_mount(debugfs_path)) | ||
573 | return; | ||
574 | |||
575 | sys_dir = opendir(debugfs_path); | ||
576 | if (!sys_dir) | ||
577 | goto cleanup; | ||
578 | |||
579 | for_each_subsystem(sys_dir, sys_dirent, sys_next, evt_path, st) { | ||
580 | evt_dir = opendir(evt_path); | ||
581 | if (!evt_dir) | ||
582 | goto cleanup; | ||
583 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next, | ||
584 | evt_path, st) { | ||
585 | snprintf(evt_path, MAXPATHLEN, "%s:%s", | ||
586 | sys_dirent.d_name, evt_dirent.d_name); | ||
587 | fprintf(stderr, " %-40s [%s]\n", evt_path, | ||
588 | event_type_descriptors[PERF_TYPE_TRACEPOINT+1]); | ||
589 | } | ||
590 | closedir(evt_dir); | ||
591 | } | ||
592 | |||
593 | cleanup: | ||
594 | closedir(sys_dir); | ||
595 | } | ||
596 | |||
597 | /* | ||
426 | * Print the help text for the event symbols: | 598 | * Print the help text for the event symbols: |
427 | */ | 599 | */ |
428 | void print_events(void) | 600 | void print_events(void) |
@@ -436,7 +608,7 @@ void print_events(void) | |||
436 | 608 | ||
437 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { | 609 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { |
438 | type = syms->type + 1; | 610 | type = syms->type + 1; |
439 | if (type > ARRAY_SIZE(event_type_descriptors)) | 611 | if (type >= ARRAY_SIZE(event_type_descriptors)) |
440 | type = 0; | 612 | type = 0; |
441 | 613 | ||
442 | if (type != prev_type) | 614 | if (type != prev_type) |
@@ -472,5 +644,7 @@ void print_events(void) | |||
472 | "rNNN"); | 644 | "rNNN"); |
473 | fprintf(stderr, "\n"); | 645 | fprintf(stderr, "\n"); |
474 | 646 | ||
647 | print_tracepoint_events(); | ||
648 | |||
475 | exit(129); | 649 | exit(129); |
476 | } | 650 | } |