Merge commit 'v2.6.32-rc7' into perf/core
[deliverable/linux.git] / tools / perf / util / parse-events.c
1
2 #include "util.h"
3 #include "../perf.h"
4 #include "parse-options.h"
5 #include "parse-events.h"
6 #include "exec_cmd.h"
7 #include "string.h"
8 #include "cache.h"
9 #include "header.h"
10 #include "debugfs.h"
11
12 int nr_counters;
13
14 struct perf_event_attr attrs[MAX_COUNTERS];
15 char *filters[MAX_COUNTERS];
16
17 struct event_symbol {
18 u8 type;
19 u64 config;
20 const char *symbol;
21 const char *alias;
22 };
23
24 enum event_result {
25 EVT_FAILED,
26 EVT_HANDLED,
27 EVT_HANDLED_ALL
28 };
29
30 char debugfs_path[MAXPATHLEN];
31
32 #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
34
35 static struct event_symbol event_symbols[] = {
36 { CHW(CPU_CYCLES), "cpu-cycles", "cycles" },
37 { CHW(INSTRUCTIONS), "instructions", "" },
38 { CHW(CACHE_REFERENCES), "cache-references", "" },
39 { CHW(CACHE_MISSES), "cache-misses", "" },
40 { CHW(BRANCH_INSTRUCTIONS), "branch-instructions", "branches" },
41 { CHW(BRANCH_MISSES), "branch-misses", "" },
42 { CHW(BUS_CYCLES), "bus-cycles", "" },
43
44 { CSW(CPU_CLOCK), "cpu-clock", "" },
45 { CSW(TASK_CLOCK), "task-clock", "" },
46 { CSW(PAGE_FAULTS), "page-faults", "faults" },
47 { CSW(PAGE_FAULTS_MIN), "minor-faults", "" },
48 { CSW(PAGE_FAULTS_MAJ), "major-faults", "" },
49 { CSW(CONTEXT_SWITCHES), "context-switches", "cs" },
50 { CSW(CPU_MIGRATIONS), "cpu-migrations", "migrations" },
51 };
52
53 #define __PERF_EVENT_FIELD(config, name) \
54 ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT)
55
56 #define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW)
57 #define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG)
58 #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE)
59 #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT)
60
61 static const char *hw_event_names[] = {
62 "cycles",
63 "instructions",
64 "cache-references",
65 "cache-misses",
66 "branches",
67 "branch-misses",
68 "bus-cycles",
69 };
70
71 static const char *sw_event_names[] = {
72 "cpu-clock-msecs",
73 "task-clock-msecs",
74 "page-faults",
75 "context-switches",
76 "CPU-migrations",
77 "minor-faults",
78 "major-faults",
79 };
80
81 #define MAX_ALIASES 8
82
83 static const char *hw_cache[][MAX_ALIASES] = {
84 { "L1-dcache", "l1-d", "l1d", "L1-data", },
85 { "L1-icache", "l1-i", "l1i", "L1-instruction", },
86 { "LLC", "L2" },
87 { "dTLB", "d-tlb", "Data-TLB", },
88 { "iTLB", "i-tlb", "Instruction-TLB", },
89 { "branch", "branches", "bpu", "btb", "bpc", },
90 };
91
92 static const char *hw_cache_op[][MAX_ALIASES] = {
93 { "load", "loads", "read", },
94 { "store", "stores", "write", },
95 { "prefetch", "prefetches", "speculative-read", "speculative-load", },
96 };
97
98 static const char *hw_cache_result[][MAX_ALIASES] = {
99 { "refs", "Reference", "ops", "access", },
100 { "misses", "miss", },
101 };
102
103 #define C(x) PERF_COUNT_HW_CACHE_##x
104 #define CACHE_READ (1 << C(OP_READ))
105 #define CACHE_WRITE (1 << C(OP_WRITE))
106 #define CACHE_PREFETCH (1 << C(OP_PREFETCH))
107 #define COP(x) (1 << x)
108
109 /*
110 * cache operartion stat
111 * L1I : Read and prefetch only
112 * ITLB and BPU : Read-only
113 */
114 static unsigned long hw_cache_stat[C(MAX)] = {
115 [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
116 [C(L1I)] = (CACHE_READ | CACHE_PREFETCH),
117 [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
118 [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
119 [C(ITLB)] = (CACHE_READ),
120 [C(BPU)] = (CACHE_READ),
121 };
122
123 #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \
124 while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
125 if (sys_dirent.d_type == DT_DIR && \
126 (strcmp(sys_dirent.d_name, ".")) && \
127 (strcmp(sys_dirent.d_name, "..")))
128
129 static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
130 {
131 char evt_path[MAXPATHLEN];
132 int fd;
133
134 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
135 sys_dir->d_name, evt_dir->d_name);
136 fd = open(evt_path, O_RDONLY);
137 if (fd < 0)
138 return -EINVAL;
139 close(fd);
140
141 return 0;
142 }
143
144 #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \
145 while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
146 if (evt_dirent.d_type == DT_DIR && \
147 (strcmp(evt_dirent.d_name, ".")) && \
148 (strcmp(evt_dirent.d_name, "..")) && \
149 (!tp_event_has_id(&sys_dirent, &evt_dirent)))
150
151 #define MAX_EVENT_LENGTH 512
152
153
154 struct tracepoint_path *tracepoint_id_to_path(u64 config)
155 {
156 struct tracepoint_path *path = NULL;
157 DIR *sys_dir, *evt_dir;
158 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
159 char id_buf[4];
160 int fd;
161 u64 id;
162 char evt_path[MAXPATHLEN];
163 char dir_path[MAXPATHLEN];
164
165 if (debugfs_valid_mountpoint(debugfs_path))
166 return NULL;
167
168 sys_dir = opendir(debugfs_path);
169 if (!sys_dir)
170 return NULL;
171
172 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
173
174 snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
175 sys_dirent.d_name);
176 evt_dir = opendir(dir_path);
177 if (!evt_dir)
178 continue;
179
180 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
181
182 snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
183 evt_dirent.d_name);
184 fd = open(evt_path, O_RDONLY);
185 if (fd < 0)
186 continue;
187 if (read(fd, id_buf, sizeof(id_buf)) < 0) {
188 close(fd);
189 continue;
190 }
191 close(fd);
192 id = atoll(id_buf);
193 if (id == config) {
194 closedir(evt_dir);
195 closedir(sys_dir);
196 path = calloc(1, sizeof(path));
197 path->system = malloc(MAX_EVENT_LENGTH);
198 if (!path->system) {
199 free(path);
200 return NULL;
201 }
202 path->name = malloc(MAX_EVENT_LENGTH);
203 if (!path->name) {
204 free(path->system);
205 free(path);
206 return NULL;
207 }
208 strncpy(path->system, sys_dirent.d_name,
209 MAX_EVENT_LENGTH);
210 strncpy(path->name, evt_dirent.d_name,
211 MAX_EVENT_LENGTH);
212 return path;
213 }
214 }
215 closedir(evt_dir);
216 }
217
218 closedir(sys_dir);
219 return NULL;
220 }
221
222 #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
223 static const char *tracepoint_id_to_name(u64 config)
224 {
225 static char buf[TP_PATH_LEN];
226 struct tracepoint_path *path;
227
228 path = tracepoint_id_to_path(config);
229 if (path) {
230 snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name);
231 free(path->name);
232 free(path->system);
233 free(path);
234 } else
235 snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown");
236
237 return buf;
238 }
239
240 static int is_cache_op_valid(u8 cache_type, u8 cache_op)
241 {
242 if (hw_cache_stat[cache_type] & COP(cache_op))
243 return 1; /* valid */
244 else
245 return 0; /* invalid */
246 }
247
248 static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
249 {
250 static char name[50];
251
252 if (cache_result) {
253 sprintf(name, "%s-%s-%s", hw_cache[cache_type][0],
254 hw_cache_op[cache_op][0],
255 hw_cache_result[cache_result][0]);
256 } else {
257 sprintf(name, "%s-%s", hw_cache[cache_type][0],
258 hw_cache_op[cache_op][1]);
259 }
260
261 return name;
262 }
263
264 const char *event_name(int counter)
265 {
266 u64 config = attrs[counter].config;
267 int type = attrs[counter].type;
268
269 return __event_name(type, config);
270 }
271
272 const char *__event_name(int type, u64 config)
273 {
274 static char buf[32];
275
276 if (type == PERF_TYPE_RAW) {
277 sprintf(buf, "raw 0x%llx", config);
278 return buf;
279 }
280
281 switch (type) {
282 case PERF_TYPE_HARDWARE:
283 if (config < PERF_COUNT_HW_MAX)
284 return hw_event_names[config];
285 return "unknown-hardware";
286
287 case PERF_TYPE_HW_CACHE: {
288 u8 cache_type, cache_op, cache_result;
289
290 cache_type = (config >> 0) & 0xff;
291 if (cache_type > PERF_COUNT_HW_CACHE_MAX)
292 return "unknown-ext-hardware-cache-type";
293
294 cache_op = (config >> 8) & 0xff;
295 if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX)
296 return "unknown-ext-hardware-cache-op";
297
298 cache_result = (config >> 16) & 0xff;
299 if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX)
300 return "unknown-ext-hardware-cache-result";
301
302 if (!is_cache_op_valid(cache_type, cache_op))
303 return "invalid-cache";
304
305 return event_cache_name(cache_type, cache_op, cache_result);
306 }
307
308 case PERF_TYPE_SOFTWARE:
309 if (config < PERF_COUNT_SW_MAX)
310 return sw_event_names[config];
311 return "unknown-software";
312
313 case PERF_TYPE_TRACEPOINT:
314 return tracepoint_id_to_name(config);
315
316 default:
317 break;
318 }
319
320 return "unknown";
321 }
322
323 static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int size)
324 {
325 int i, j;
326 int n, longest = -1;
327
328 for (i = 0; i < size; i++) {
329 for (j = 0; j < MAX_ALIASES && names[i][j]; j++) {
330 n = strlen(names[i][j]);
331 if (n > longest && !strncasecmp(*str, names[i][j], n))
332 longest = n;
333 }
334 if (longest > 0) {
335 *str += longest;
336 return i;
337 }
338 }
339
340 return -1;
341 }
342
343 static enum event_result
344 parse_generic_hw_event(const char **str, struct perf_event_attr *attr)
345 {
346 const char *s = *str;
347 int cache_type = -1, cache_op = -1, cache_result = -1;
348
349 cache_type = parse_aliases(&s, hw_cache, PERF_COUNT_HW_CACHE_MAX);
350 /*
351 * No fallback - if we cannot get a clear cache type
352 * then bail out:
353 */
354 if (cache_type == -1)
355 return EVT_FAILED;
356
357 while ((cache_op == -1 || cache_result == -1) && *s == '-') {
358 ++s;
359
360 if (cache_op == -1) {
361 cache_op = parse_aliases(&s, hw_cache_op,
362 PERF_COUNT_HW_CACHE_OP_MAX);
363 if (cache_op >= 0) {
364 if (!is_cache_op_valid(cache_type, cache_op))
365 return 0;
366 continue;
367 }
368 }
369
370 if (cache_result == -1) {
371 cache_result = parse_aliases(&s, hw_cache_result,
372 PERF_COUNT_HW_CACHE_RESULT_MAX);
373 if (cache_result >= 0)
374 continue;
375 }
376
377 /*
378 * Can't parse this as a cache op or result, so back up
379 * to the '-'.
380 */
381 --s;
382 break;
383 }
384
385 /*
386 * Fall back to reads:
387 */
388 if (cache_op == -1)
389 cache_op = PERF_COUNT_HW_CACHE_OP_READ;
390
391 /*
392 * Fall back to accesses:
393 */
394 if (cache_result == -1)
395 cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS;
396
397 attr->config = cache_type | (cache_op << 8) | (cache_result << 16);
398 attr->type = PERF_TYPE_HW_CACHE;
399
400 *str = s;
401 return EVT_HANDLED;
402 }
403
404 static enum event_result
405 parse_single_tracepoint_event(char *sys_name,
406 const char *evt_name,
407 unsigned int evt_length,
408 char *flags,
409 struct perf_event_attr *attr,
410 const char **strp)
411 {
412 char evt_path[MAXPATHLEN];
413 char id_buf[4];
414 u64 id;
415 int fd;
416
417 if (flags) {
418 if (!strncmp(flags, "record", strlen(flags))) {
419 attr->sample_type |= PERF_SAMPLE_RAW;
420 attr->sample_type |= PERF_SAMPLE_TIME;
421 attr->sample_type |= PERF_SAMPLE_CPU;
422 }
423 }
424
425 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
426 sys_name, evt_name);
427
428 fd = open(evt_path, O_RDONLY);
429 if (fd < 0)
430 return EVT_FAILED;
431
432 if (read(fd, id_buf, sizeof(id_buf)) < 0) {
433 close(fd);
434 return EVT_FAILED;
435 }
436
437 close(fd);
438 id = atoll(id_buf);
439 attr->config = id;
440 attr->type = PERF_TYPE_TRACEPOINT;
441 *strp = evt_name + evt_length;
442
443 return EVT_HANDLED;
444 }
445
446 /* sys + ':' + event + ':' + flags*/
447 #define MAX_EVOPT_LEN (MAX_EVENT_LENGTH * 2 + 2 + 128)
448 static enum event_result
449 parse_subsystem_tracepoint_event(char *sys_name, char *flags)
450 {
451 char evt_path[MAXPATHLEN];
452 struct dirent *evt_ent;
453 DIR *evt_dir;
454
455 snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name);
456 evt_dir = opendir(evt_path);
457
458 if (!evt_dir) {
459 perror("Can't open event dir");
460 return EVT_FAILED;
461 }
462
463 while ((evt_ent = readdir(evt_dir))) {
464 char event_opt[MAX_EVOPT_LEN + 1];
465 int len;
466 unsigned int rem = MAX_EVOPT_LEN;
467
468 if (!strcmp(evt_ent->d_name, ".")
469 || !strcmp(evt_ent->d_name, "..")
470 || !strcmp(evt_ent->d_name, "enable")
471 || !strcmp(evt_ent->d_name, "filter"))
472 continue;
473
474 len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s", sys_name,
475 evt_ent->d_name);
476 if (len < 0)
477 return EVT_FAILED;
478
479 rem -= len;
480 if (flags) {
481 if (rem < strlen(flags) + 1)
482 return EVT_FAILED;
483
484 strcat(event_opt, ":");
485 strcat(event_opt, flags);
486 }
487
488 if (parse_events(NULL, event_opt, 0))
489 return EVT_FAILED;
490 }
491
492 return EVT_HANDLED_ALL;
493 }
494
495
496 static enum event_result parse_tracepoint_event(const char **strp,
497 struct perf_event_attr *attr)
498 {
499 const char *evt_name;
500 char *flags;
501 char sys_name[MAX_EVENT_LENGTH];
502 unsigned int sys_length, evt_length;
503
504 if (debugfs_valid_mountpoint(debugfs_path))
505 return 0;
506
507 evt_name = strchr(*strp, ':');
508 if (!evt_name)
509 return EVT_FAILED;
510
511 sys_length = evt_name - *strp;
512 if (sys_length >= MAX_EVENT_LENGTH)
513 return 0;
514
515 strncpy(sys_name, *strp, sys_length);
516 sys_name[sys_length] = '\0';
517 evt_name = evt_name + 1;
518
519 flags = strchr(evt_name, ':');
520 if (flags) {
521 /* split it out: */
522 evt_name = strndup(evt_name, flags - evt_name);
523 flags++;
524 }
525
526 evt_length = strlen(evt_name);
527 if (evt_length >= MAX_EVENT_LENGTH)
528 return EVT_FAILED;
529
530 if (!strcmp(evt_name, "*")) {
531 *strp = evt_name + evt_length;
532 return parse_subsystem_tracepoint_event(sys_name, flags);
533 } else
534 return parse_single_tracepoint_event(sys_name, evt_name,
535 evt_length, flags,
536 attr, strp);
537 }
538
539 static int check_events(const char *str, unsigned int i)
540 {
541 int n;
542
543 n = strlen(event_symbols[i].symbol);
544 if (!strncmp(str, event_symbols[i].symbol, n))
545 return n;
546
547 n = strlen(event_symbols[i].alias);
548 if (n)
549 if (!strncmp(str, event_symbols[i].alias, n))
550 return n;
551 return 0;
552 }
553
554 static enum event_result
555 parse_symbolic_event(const char **strp, struct perf_event_attr *attr)
556 {
557 const char *str = *strp;
558 unsigned int i;
559 int n;
560
561 for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
562 n = check_events(str, i);
563 if (n > 0) {
564 attr->type = event_symbols[i].type;
565 attr->config = event_symbols[i].config;
566 *strp = str + n;
567 return EVT_HANDLED;
568 }
569 }
570 return EVT_FAILED;
571 }
572
573 static enum event_result
574 parse_raw_event(const char **strp, struct perf_event_attr *attr)
575 {
576 const char *str = *strp;
577 u64 config;
578 int n;
579
580 if (*str != 'r')
581 return EVT_FAILED;
582 n = hex2u64(str + 1, &config);
583 if (n > 0) {
584 *strp = str + n + 1;
585 attr->type = PERF_TYPE_RAW;
586 attr->config = config;
587 return EVT_HANDLED;
588 }
589 return EVT_FAILED;
590 }
591
592 static enum event_result
593 parse_numeric_event(const char **strp, struct perf_event_attr *attr)
594 {
595 const char *str = *strp;
596 char *endp;
597 unsigned long type;
598 u64 config;
599
600 type = strtoul(str, &endp, 0);
601 if (endp > str && type < PERF_TYPE_MAX && *endp == ':') {
602 str = endp + 1;
603 config = strtoul(str, &endp, 0);
604 if (endp > str) {
605 attr->type = type;
606 attr->config = config;
607 *strp = endp;
608 return EVT_HANDLED;
609 }
610 }
611 return EVT_FAILED;
612 }
613
614 static enum event_result
615 parse_event_modifier(const char **strp, struct perf_event_attr *attr)
616 {
617 const char *str = *strp;
618 int eu = 1, ek = 1, eh = 1;
619
620 if (*str++ != ':')
621 return 0;
622 while (*str) {
623 if (*str == 'u')
624 eu = 0;
625 else if (*str == 'k')
626 ek = 0;
627 else if (*str == 'h')
628 eh = 0;
629 else
630 break;
631 ++str;
632 }
633 if (str >= *strp + 2) {
634 *strp = str;
635 attr->exclude_user = eu;
636 attr->exclude_kernel = ek;
637 attr->exclude_hv = eh;
638 return 1;
639 }
640 return 0;
641 }
642
643 /*
644 * Each event can have multiple symbolic names.
645 * Symbolic names are (almost) exactly matched.
646 */
647 static enum event_result
648 parse_event_symbols(const char **str, struct perf_event_attr *attr)
649 {
650 enum event_result ret;
651
652 ret = parse_tracepoint_event(str, attr);
653 if (ret != EVT_FAILED)
654 goto modifier;
655
656 ret = parse_raw_event(str, attr);
657 if (ret != EVT_FAILED)
658 goto modifier;
659
660 ret = parse_numeric_event(str, attr);
661 if (ret != EVT_FAILED)
662 goto modifier;
663
664 ret = parse_symbolic_event(str, attr);
665 if (ret != EVT_FAILED)
666 goto modifier;
667
668 ret = parse_generic_hw_event(str, attr);
669 if (ret != EVT_FAILED)
670 goto modifier;
671
672 fprintf(stderr, "invalid or unsupported event: '%s'\n", *str);
673 fprintf(stderr, "Run 'perf list' for a list of valid events\n");
674 return EVT_FAILED;
675
676 modifier:
677 parse_event_modifier(str, attr);
678
679 return ret;
680 }
681
682 static void store_event_type(const char *orgname)
683 {
684 char filename[PATH_MAX], *c;
685 FILE *file;
686 int id;
687
688 sprintf(filename, "%s/", debugfs_path);
689 strncat(filename, orgname, strlen(orgname));
690 strcat(filename, "/id");
691
692 c = strchr(filename, ':');
693 if (c)
694 *c = '/';
695
696 file = fopen(filename, "r");
697 if (!file)
698 return;
699 if (fscanf(file, "%i", &id) < 1)
700 die("cannot store event ID");
701 fclose(file);
702 perf_header__push_event(id, orgname);
703 }
704
705 int parse_events(const struct option *opt __used, const char *str, int unset __used)
706 {
707 struct perf_event_attr attr;
708 enum event_result ret;
709
710 if (strchr(str, ':'))
711 store_event_type(str);
712
713 for (;;) {
714 if (nr_counters == MAX_COUNTERS)
715 return -1;
716
717 memset(&attr, 0, sizeof(attr));
718 ret = parse_event_symbols(&str, &attr);
719 if (ret == EVT_FAILED)
720 return -1;
721
722 if (!(*str == 0 || *str == ',' || isspace(*str)))
723 return -1;
724
725 if (ret != EVT_HANDLED_ALL) {
726 attrs[nr_counters] = attr;
727 nr_counters++;
728 }
729
730 if (*str == 0)
731 break;
732 if (*str == ',')
733 ++str;
734 while (isspace(*str))
735 ++str;
736 }
737
738 return 0;
739 }
740
741 int parse_filter(const struct option *opt __used, const char *str,
742 int unset __used)
743 {
744 int i = nr_counters - 1;
745 int len = strlen(str);
746
747 if (i < 0 || attrs[i].type != PERF_TYPE_TRACEPOINT) {
748 fprintf(stderr,
749 "-F option should follow a -e tracepoint option\n");
750 return -1;
751 }
752
753 filters[i] = malloc(len + 1);
754 if (!filters[i]) {
755 fprintf(stderr, "not enough memory to hold filter string\n");
756 return -1;
757 }
758 strcpy(filters[i], str);
759
760 return 0;
761 }
762
763 static const char * const event_type_descriptors[] = {
764 "",
765 "Hardware event",
766 "Software event",
767 "Tracepoint event",
768 "Hardware cache event",
769 };
770
771 /*
772 * Print the events from <debugfs_mount_point>/tracing/events
773 */
774
775 static void print_tracepoint_events(void)
776 {
777 DIR *sys_dir, *evt_dir;
778 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
779 char evt_path[MAXPATHLEN];
780 char dir_path[MAXPATHLEN];
781
782 if (debugfs_valid_mountpoint(debugfs_path))
783 return;
784
785 sys_dir = opendir(debugfs_path);
786 if (!sys_dir)
787 return;
788
789 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
790
791 snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
792 sys_dirent.d_name);
793 evt_dir = opendir(dir_path);
794 if (!evt_dir)
795 continue;
796
797 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
798 snprintf(evt_path, MAXPATHLEN, "%s:%s",
799 sys_dirent.d_name, evt_dirent.d_name);
800 printf(" %-42s [%s]\n", evt_path,
801 event_type_descriptors[PERF_TYPE_TRACEPOINT+1]);
802 }
803 closedir(evt_dir);
804 }
805 closedir(sys_dir);
806 }
807
808 /*
809 * Print the help text for the event symbols:
810 */
811 void print_events(void)
812 {
813 struct event_symbol *syms = event_symbols;
814 unsigned int i, type, op, prev_type = -1;
815 char name[40];
816
817 printf("\n");
818 printf("List of pre-defined events (to be used in -e):\n");
819
820 for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
821 type = syms->type + 1;
822 if (type >= ARRAY_SIZE(event_type_descriptors))
823 type = 0;
824
825 if (type != prev_type)
826 printf("\n");
827
828 if (strlen(syms->alias))
829 sprintf(name, "%s OR %s", syms->symbol, syms->alias);
830 else
831 strcpy(name, syms->symbol);
832 printf(" %-42s [%s]\n", name,
833 event_type_descriptors[type]);
834
835 prev_type = type;
836 }
837
838 printf("\n");
839 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
840 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
841 /* skip invalid cache type */
842 if (!is_cache_op_valid(type, op))
843 continue;
844
845 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
846 printf(" %-42s [%s]\n",
847 event_cache_name(type, op, i),
848 event_type_descriptors[4]);
849 }
850 }
851 }
852
853 printf("\n");
854 printf(" %-42s [raw hardware event descriptor]\n",
855 "rNNN");
856 printf("\n");
857
858 print_tracepoint_events();
859
860 exit(129);
861 }
This page took 0.091384 seconds and 6 git commands to generate.