1 #include "../../../include/linux/hw_breakpoint.h"
6 #include "parse-options.h"
7 #include "parse-events.h"
28 char debugfs_path
[MAXPATHLEN
];
30 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
31 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
33 static struct event_symbol event_symbols
[] = {
34 { CHW(CPU_CYCLES
), "cpu-cycles", "cycles" },
35 { CHW(STALLED_CYCLES_FRONTEND
), "stalled-cycles-frontend", "idle-cycles-frontend" },
36 { CHW(STALLED_CYCLES_BACKEND
), "stalled-cycles-backend", "idle-cycles-backend" },
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", "" },
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 { CSW(ALIGNMENT_FAULTS
), "alignment-faults", "" },
52 { CSW(EMULATION_FAULTS
), "emulation-faults", "" },
55 #define __PERF_EVENT_FIELD(config, name) \
56 ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT)
58 #define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW)
59 #define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG)
60 #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE)
61 #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT)
63 static const char *hw_event_names
[PERF_COUNT_HW_MAX
] = {
71 "stalled-cycles-frontend",
72 "stalled-cycles-backend",
75 static const char *sw_event_names
[PERF_COUNT_SW_MAX
] = {
89 static const char *hw_cache
[][MAX_ALIASES
] = {
90 { "L1-dcache", "l1-d", "l1d", "L1-data", },
91 { "L1-icache", "l1-i", "l1i", "L1-instruction", },
93 { "dTLB", "d-tlb", "Data-TLB", },
94 { "iTLB", "i-tlb", "Instruction-TLB", },
95 { "branch", "branches", "bpu", "btb", "bpc", },
98 static const char *hw_cache_op
[][MAX_ALIASES
] = {
99 { "load", "loads", "read", },
100 { "store", "stores", "write", },
101 { "prefetch", "prefetches", "speculative-read", "speculative-load", },
104 static const char *hw_cache_result
[][MAX_ALIASES
] = {
105 { "refs", "Reference", "ops", "access", },
106 { "misses", "miss", },
109 #define C(x) PERF_COUNT_HW_CACHE_##x
110 #define CACHE_READ (1 << C(OP_READ))
111 #define CACHE_WRITE (1 << C(OP_WRITE))
112 #define CACHE_PREFETCH (1 << C(OP_PREFETCH))
113 #define COP(x) (1 << x)
116 * cache operartion stat
117 * L1I : Read and prefetch only
118 * ITLB and BPU : Read-only
120 static unsigned long hw_cache_stat
[C(MAX
)] = {
121 [C(L1D
)] = (CACHE_READ
| CACHE_WRITE
| CACHE_PREFETCH
),
122 [C(L1I
)] = (CACHE_READ
| CACHE_PREFETCH
),
123 [C(LL
)] = (CACHE_READ
| CACHE_WRITE
| CACHE_PREFETCH
),
124 [C(DTLB
)] = (CACHE_READ
| CACHE_WRITE
| CACHE_PREFETCH
),
125 [C(ITLB
)] = (CACHE_READ
),
126 [C(BPU
)] = (CACHE_READ
),
129 #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \
130 while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
131 if (sys_dirent.d_type == DT_DIR && \
132 (strcmp(sys_dirent.d_name, ".")) && \
133 (strcmp(sys_dirent.d_name, "..")))
135 static int tp_event_has_id(struct dirent
*sys_dir
, struct dirent
*evt_dir
)
137 char evt_path
[MAXPATHLEN
];
140 snprintf(evt_path
, MAXPATHLEN
, "%s/%s/%s/id", debugfs_path
,
141 sys_dir
->d_name
, evt_dir
->d_name
);
142 fd
= open(evt_path
, O_RDONLY
);
150 #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \
151 while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
152 if (evt_dirent.d_type == DT_DIR && \
153 (strcmp(evt_dirent.d_name, ".")) && \
154 (strcmp(evt_dirent.d_name, "..")) && \
155 (!tp_event_has_id(&sys_dirent, &evt_dirent)))
157 #define MAX_EVENT_LENGTH 512
160 struct tracepoint_path
*tracepoint_id_to_path(u64 config
)
162 struct tracepoint_path
*path
= NULL
;
163 DIR *sys_dir
, *evt_dir
;
164 struct dirent
*sys_next
, *evt_next
, sys_dirent
, evt_dirent
;
168 char evt_path
[MAXPATHLEN
];
169 char dir_path
[MAXPATHLEN
];
171 if (debugfs_valid_mountpoint(debugfs_path
))
174 sys_dir
= opendir(debugfs_path
);
178 for_each_subsystem(sys_dir
, sys_dirent
, sys_next
) {
180 snprintf(dir_path
, MAXPATHLEN
, "%s/%s", debugfs_path
,
182 evt_dir
= opendir(dir_path
);
186 for_each_event(sys_dirent
, evt_dir
, evt_dirent
, evt_next
) {
188 snprintf(evt_path
, MAXPATHLEN
, "%s/%s/id", dir_path
,
190 fd
= open(evt_path
, O_RDONLY
);
193 if (read(fd
, id_buf
, sizeof(id_buf
)) < 0) {
202 path
= zalloc(sizeof(*path
));
203 path
->system
= malloc(MAX_EVENT_LENGTH
);
208 path
->name
= malloc(MAX_EVENT_LENGTH
);
214 strncpy(path
->system
, sys_dirent
.d_name
,
216 strncpy(path
->name
, evt_dirent
.d_name
,
228 #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
229 static const char *tracepoint_id_to_name(u64 config
)
231 static char buf
[TP_PATH_LEN
];
232 struct tracepoint_path
*path
;
234 path
= tracepoint_id_to_path(config
);
236 snprintf(buf
, TP_PATH_LEN
, "%s:%s", path
->system
, path
->name
);
241 snprintf(buf
, TP_PATH_LEN
, "%s:%s", "unknown", "unknown");
246 static int is_cache_op_valid(u8 cache_type
, u8 cache_op
)
248 if (hw_cache_stat
[cache_type
] & COP(cache_op
))
249 return 1; /* valid */
251 return 0; /* invalid */
254 static char *event_cache_name(u8 cache_type
, u8 cache_op
, u8 cache_result
)
256 static char name
[50];
259 sprintf(name
, "%s-%s-%s", hw_cache
[cache_type
][0],
260 hw_cache_op
[cache_op
][0],
261 hw_cache_result
[cache_result
][0]);
263 sprintf(name
, "%s-%s", hw_cache
[cache_type
][0],
264 hw_cache_op
[cache_op
][1]);
270 const char *event_type(int type
)
273 case PERF_TYPE_HARDWARE
:
276 case PERF_TYPE_SOFTWARE
:
279 case PERF_TYPE_TRACEPOINT
:
282 case PERF_TYPE_HW_CACHE
:
283 return "hardware-cache";
292 const char *event_name(struct perf_evsel
*evsel
)
294 u64 config
= evsel
->attr
.config
;
295 int type
= evsel
->attr
.type
;
300 return __event_name(type
, config
);
303 const char *__event_name(int type
, u64 config
)
307 if (type
== PERF_TYPE_RAW
) {
308 sprintf(buf
, "raw 0x%" PRIx64
, config
);
313 case PERF_TYPE_HARDWARE
:
314 if (config
< PERF_COUNT_HW_MAX
&& hw_event_names
[config
])
315 return hw_event_names
[config
];
316 return "unknown-hardware";
318 case PERF_TYPE_HW_CACHE
: {
319 u8 cache_type
, cache_op
, cache_result
;
321 cache_type
= (config
>> 0) & 0xff;
322 if (cache_type
> PERF_COUNT_HW_CACHE_MAX
)
323 return "unknown-ext-hardware-cache-type";
325 cache_op
= (config
>> 8) & 0xff;
326 if (cache_op
> PERF_COUNT_HW_CACHE_OP_MAX
)
327 return "unknown-ext-hardware-cache-op";
329 cache_result
= (config
>> 16) & 0xff;
330 if (cache_result
> PERF_COUNT_HW_CACHE_RESULT_MAX
)
331 return "unknown-ext-hardware-cache-result";
333 if (!is_cache_op_valid(cache_type
, cache_op
))
334 return "invalid-cache";
336 return event_cache_name(cache_type
, cache_op
, cache_result
);
339 case PERF_TYPE_SOFTWARE
:
340 if (config
< PERF_COUNT_SW_MAX
&& sw_event_names
[config
])
341 return sw_event_names
[config
];
342 return "unknown-software";
344 case PERF_TYPE_TRACEPOINT
:
345 return tracepoint_id_to_name(config
);
354 static int parse_aliases(const char **str
, const char *names
[][MAX_ALIASES
], int size
)
359 for (i
= 0; i
< size
; i
++) {
360 for (j
= 0; j
< MAX_ALIASES
&& names
[i
][j
]; j
++) {
361 n
= strlen(names
[i
][j
]);
362 if (n
> longest
&& !strncasecmp(*str
, names
[i
][j
], n
))
374 static enum event_result
375 parse_generic_hw_event(const char **str
, struct perf_event_attr
*attr
)
377 const char *s
= *str
;
378 int cache_type
= -1, cache_op
= -1, cache_result
= -1;
380 cache_type
= parse_aliases(&s
, hw_cache
, PERF_COUNT_HW_CACHE_MAX
);
382 * No fallback - if we cannot get a clear cache type
385 if (cache_type
== -1)
388 while ((cache_op
== -1 || cache_result
== -1) && *s
== '-') {
391 if (cache_op
== -1) {
392 cache_op
= parse_aliases(&s
, hw_cache_op
,
393 PERF_COUNT_HW_CACHE_OP_MAX
);
395 if (!is_cache_op_valid(cache_type
, cache_op
))
401 if (cache_result
== -1) {
402 cache_result
= parse_aliases(&s
, hw_cache_result
,
403 PERF_COUNT_HW_CACHE_RESULT_MAX
);
404 if (cache_result
>= 0)
409 * Can't parse this as a cache op or result, so back up
417 * Fall back to reads:
420 cache_op
= PERF_COUNT_HW_CACHE_OP_READ
;
423 * Fall back to accesses:
425 if (cache_result
== -1)
426 cache_result
= PERF_COUNT_HW_CACHE_RESULT_ACCESS
;
428 attr
->config
= cache_type
| (cache_op
<< 8) | (cache_result
<< 16);
429 attr
->type
= PERF_TYPE_HW_CACHE
;
435 static enum event_result
436 parse_single_tracepoint_event(char *sys_name
,
437 const char *evt_name
,
438 unsigned int evt_length
,
439 struct perf_event_attr
*attr
,
442 char evt_path
[MAXPATHLEN
];
447 snprintf(evt_path
, MAXPATHLEN
, "%s/%s/%s/id", debugfs_path
,
450 fd
= open(evt_path
, O_RDONLY
);
454 if (read(fd
, id_buf
, sizeof(id_buf
)) < 0) {
462 attr
->type
= PERF_TYPE_TRACEPOINT
;
463 *strp
+= strlen(sys_name
) + evt_length
+ 1; /* + 1 for the ':' */
465 attr
->sample_type
|= PERF_SAMPLE_RAW
;
466 attr
->sample_type
|= PERF_SAMPLE_TIME
;
467 attr
->sample_type
|= PERF_SAMPLE_CPU
;
469 attr
->sample_period
= 1;
475 /* sys + ':' + event + ':' + flags*/
476 #define MAX_EVOPT_LEN (MAX_EVENT_LENGTH * 2 + 2 + 128)
477 static enum event_result
478 parse_multiple_tracepoint_event(const struct option
*opt
, char *sys_name
,
479 const char *evt_exp
, char *flags
)
481 char evt_path
[MAXPATHLEN
];
482 struct dirent
*evt_ent
;
485 snprintf(evt_path
, MAXPATHLEN
, "%s/%s", debugfs_path
, sys_name
);
486 evt_dir
= opendir(evt_path
);
489 perror("Can't open event dir");
493 while ((evt_ent
= readdir(evt_dir
))) {
494 char event_opt
[MAX_EVOPT_LEN
+ 1];
497 if (!strcmp(evt_ent
->d_name
, ".")
498 || !strcmp(evt_ent
->d_name
, "..")
499 || !strcmp(evt_ent
->d_name
, "enable")
500 || !strcmp(evt_ent
->d_name
, "filter"))
503 if (!strglobmatch(evt_ent
->d_name
, evt_exp
))
506 len
= snprintf(event_opt
, MAX_EVOPT_LEN
, "%s:%s%s%s", sys_name
,
507 evt_ent
->d_name
, flags
? ":" : "",
512 if (parse_events(opt
, event_opt
, 0))
516 return EVT_HANDLED_ALL
;
519 static enum event_result
520 parse_tracepoint_event(const struct option
*opt
, const char **strp
,
521 struct perf_event_attr
*attr
)
523 const char *evt_name
;
524 char *flags
= NULL
, *comma_loc
;
525 char sys_name
[MAX_EVENT_LENGTH
];
526 unsigned int sys_length
, evt_length
;
528 if (debugfs_valid_mountpoint(debugfs_path
))
531 evt_name
= strchr(*strp
, ':');
535 sys_length
= evt_name
- *strp
;
536 if (sys_length
>= MAX_EVENT_LENGTH
)
539 strncpy(sys_name
, *strp
, sys_length
);
540 sys_name
[sys_length
] = '\0';
541 evt_name
= evt_name
+ 1;
543 comma_loc
= strchr(evt_name
, ',');
545 /* take the event name up to the comma */
546 evt_name
= strndup(evt_name
, comma_loc
- evt_name
);
548 flags
= strchr(evt_name
, ':');
551 evt_name
= strndup(evt_name
, flags
- evt_name
);
555 evt_length
= strlen(evt_name
);
556 if (evt_length
>= MAX_EVENT_LENGTH
)
558 if (strpbrk(evt_name
, "*?")) {
559 *strp
+= strlen(sys_name
) + evt_length
+ 1; /* 1 == the ':' */
560 return parse_multiple_tracepoint_event(opt
, sys_name
, evt_name
,
563 return parse_single_tracepoint_event(sys_name
, evt_name
,
564 evt_length
, attr
, strp
);
568 static enum event_result
569 parse_breakpoint_type(const char *type
, const char **strp
,
570 struct perf_event_attr
*attr
)
574 for (i
= 0; i
< 3; i
++) {
580 attr
->bp_type
|= HW_BREAKPOINT_R
;
583 attr
->bp_type
|= HW_BREAKPOINT_W
;
586 attr
->bp_type
|= HW_BREAKPOINT_X
;
592 if (!attr
->bp_type
) /* Default */
593 attr
->bp_type
= HW_BREAKPOINT_R
| HW_BREAKPOINT_W
;
600 static enum event_result
601 parse_breakpoint_event(const char **strp
, struct perf_event_attr
*attr
)
607 enum event_result err
;
609 target
= strchr(*strp
, ':');
613 if (strncmp(*strp
, "mem", target
- *strp
) != 0)
618 addr
= strtoull(target
, &endaddr
, 0);
619 if (target
== endaddr
)
622 attr
->bp_addr
= addr
;
625 type
= strchr(target
, ':');
627 /* If no type is defined, just rw as default */
629 attr
->bp_type
= HW_BREAKPOINT_R
| HW_BREAKPOINT_W
;
631 err
= parse_breakpoint_type(++type
, strp
, attr
);
632 if (err
== EVT_FAILED
)
637 * We should find a nice way to override the access length
638 * Provide some defaults for now
640 if (attr
->bp_type
== HW_BREAKPOINT_X
)
641 attr
->bp_len
= sizeof(long);
643 attr
->bp_len
= HW_BREAKPOINT_LEN_4
;
645 attr
->type
= PERF_TYPE_BREAKPOINT
;
650 static int check_events(const char *str
, unsigned int i
)
654 n
= strlen(event_symbols
[i
].symbol
);
655 if (!strncasecmp(str
, event_symbols
[i
].symbol
, n
))
658 n
= strlen(event_symbols
[i
].alias
);
660 if (!strncasecmp(str
, event_symbols
[i
].alias
, n
))
667 static enum event_result
668 parse_symbolic_event(const char **strp
, struct perf_event_attr
*attr
)
670 const char *str
= *strp
;
674 for (i
= 0; i
< ARRAY_SIZE(event_symbols
); i
++) {
675 n
= check_events(str
, i
);
677 attr
->type
= event_symbols
[i
].type
;
678 attr
->config
= event_symbols
[i
].config
;
686 static enum event_result
687 parse_raw_event(const char **strp
, struct perf_event_attr
*attr
)
689 const char *str
= *strp
;
695 n
= hex2u64(str
+ 1, &config
);
698 attr
->type
= PERF_TYPE_RAW
;
699 attr
->config
= config
;
705 static enum event_result
706 parse_numeric_event(const char **strp
, struct perf_event_attr
*attr
)
708 const char *str
= *strp
;
713 type
= strtoul(str
, &endp
, 0);
714 if (endp
> str
&& type
< PERF_TYPE_MAX
&& *endp
== ':') {
716 config
= strtoul(str
, &endp
, 0);
719 attr
->config
= config
;
728 parse_event_modifier(const char **strp
, struct perf_event_attr
*attr
)
730 const char *str
= *strp
;
732 int eu
= 0, ek
= 0, eh
= 0, precise
= 0;
746 exclude
= eu
= ek
= eh
= 1;
748 } else if (*str
== 'k') {
750 exclude
= eu
= ek
= eh
= 1;
752 } else if (*str
== 'h') {
754 exclude
= eu
= ek
= eh
= 1;
756 } else if (*str
== 'p') {
768 attr
->exclude_user
= eu
;
769 attr
->exclude_kernel
= ek
;
770 attr
->exclude_hv
= eh
;
771 attr
->precise_ip
= precise
;
777 * Each event can have multiple symbolic names.
778 * Symbolic names are (almost) exactly matched.
780 static enum event_result
781 parse_event_symbols(const struct option
*opt
, const char **str
,
782 struct perf_event_attr
*attr
)
784 enum event_result ret
;
786 ret
= parse_tracepoint_event(opt
, str
, attr
);
787 if (ret
!= EVT_FAILED
)
790 ret
= parse_raw_event(str
, attr
);
791 if (ret
!= EVT_FAILED
)
794 ret
= parse_numeric_event(str
, attr
);
795 if (ret
!= EVT_FAILED
)
798 ret
= parse_symbolic_event(str
, attr
);
799 if (ret
!= EVT_FAILED
)
802 ret
= parse_generic_hw_event(str
, attr
);
803 if (ret
!= EVT_FAILED
)
806 ret
= parse_breakpoint_event(str
, attr
);
807 if (ret
!= EVT_FAILED
)
810 fprintf(stderr
, "invalid or unsupported event: '%s'\n", *str
);
811 fprintf(stderr
, "Run 'perf list' for a list of valid events\n");
815 if (parse_event_modifier(str
, attr
) < 0) {
816 fprintf(stderr
, "invalid event modifier: '%s'\n", *str
);
817 fprintf(stderr
, "Run 'perf list' for a list of valid events and modifiers\n");
825 int parse_events(const struct option
*opt
, const char *str
, int unset __used
)
827 struct perf_evlist
*evlist
= *(struct perf_evlist
**)opt
->value
;
828 struct perf_event_attr attr
;
829 enum event_result ret
;
834 memset(&attr
, 0, sizeof(attr
));
835 ret
= parse_event_symbols(opt
, &str
, &attr
);
836 if (ret
== EVT_FAILED
)
839 if (!(*str
== 0 || *str
== ',' || isspace(*str
)))
842 if (ret
!= EVT_HANDLED_ALL
) {
843 struct perf_evsel
*evsel
;
844 evsel
= perf_evsel__new(&attr
, evlist
->nr_entries
);
847 perf_evlist__add(evlist
, evsel
);
849 evsel
->name
= calloc(str
- ostr
+ 1, 1);
852 strncpy(evsel
->name
, ostr
, str
- ostr
);
859 while (isspace(*str
))
866 int parse_filter(const struct option
*opt
, const char *str
,
869 struct perf_evlist
*evlist
= *(struct perf_evlist
**)opt
->value
;
870 struct perf_evsel
*last
= NULL
;
872 if (evlist
->nr_entries
> 0)
873 last
= list_entry(evlist
->entries
.prev
, struct perf_evsel
, node
);
875 if (last
== NULL
|| last
->attr
.type
!= PERF_TYPE_TRACEPOINT
) {
877 "-F option should follow a -e tracepoint option\n");
881 last
->filter
= strdup(str
);
882 if (last
->filter
== NULL
) {
883 fprintf(stderr
, "not enough memory to hold filter string\n");
890 static const char * const event_type_descriptors
[] = {
894 "Hardware cache event",
895 "Raw hardware event descriptor",
896 "Hardware breakpoint",
900 * Print the events from <debugfs_mount_point>/tracing/events
903 void print_tracepoint_events(const char *subsys_glob
, const char *event_glob
)
905 DIR *sys_dir
, *evt_dir
;
906 struct dirent
*sys_next
, *evt_next
, sys_dirent
, evt_dirent
;
907 char evt_path
[MAXPATHLEN
];
908 char dir_path
[MAXPATHLEN
];
910 if (debugfs_valid_mountpoint(debugfs_path
))
913 sys_dir
= opendir(debugfs_path
);
917 for_each_subsystem(sys_dir
, sys_dirent
, sys_next
) {
918 if (subsys_glob
!= NULL
&&
919 !strglobmatch(sys_dirent
.d_name
, subsys_glob
))
922 snprintf(dir_path
, MAXPATHLEN
, "%s/%s", debugfs_path
,
924 evt_dir
= opendir(dir_path
);
928 for_each_event(sys_dirent
, evt_dir
, evt_dirent
, evt_next
) {
929 if (event_glob
!= NULL
&&
930 !strglobmatch(evt_dirent
.d_name
, event_glob
))
933 snprintf(evt_path
, MAXPATHLEN
, "%s:%s",
934 sys_dirent
.d_name
, evt_dirent
.d_name
);
935 printf(" %-50s [%s]\n", evt_path
,
936 event_type_descriptors
[PERF_TYPE_TRACEPOINT
]);
944 * Check whether event is in <debugfs_mount_point>/tracing/events
947 int is_valid_tracepoint(const char *event_string
)
949 DIR *sys_dir
, *evt_dir
;
950 struct dirent
*sys_next
, *evt_next
, sys_dirent
, evt_dirent
;
951 char evt_path
[MAXPATHLEN
];
952 char dir_path
[MAXPATHLEN
];
954 if (debugfs_valid_mountpoint(debugfs_path
))
957 sys_dir
= opendir(debugfs_path
);
961 for_each_subsystem(sys_dir
, sys_dirent
, sys_next
) {
963 snprintf(dir_path
, MAXPATHLEN
, "%s/%s", debugfs_path
,
965 evt_dir
= opendir(dir_path
);
969 for_each_event(sys_dirent
, evt_dir
, evt_dirent
, evt_next
) {
970 snprintf(evt_path
, MAXPATHLEN
, "%s:%s",
971 sys_dirent
.d_name
, evt_dirent
.d_name
);
972 if (!strcmp(evt_path
, event_string
)) {
984 void print_events_type(u8 type
)
986 struct event_symbol
*syms
= event_symbols
;
990 for (i
= 0; i
< ARRAY_SIZE(event_symbols
); i
++, syms
++) {
991 if (type
!= syms
->type
)
994 if (strlen(syms
->alias
))
995 snprintf(name
, sizeof(name
), "%s OR %s",
996 syms
->symbol
, syms
->alias
);
998 snprintf(name
, sizeof(name
), "%s", syms
->symbol
);
1000 printf(" %-50s [%s]\n", name
,
1001 event_type_descriptors
[type
]);
1005 int print_hwcache_events(const char *event_glob
)
1007 unsigned int type
, op
, i
, printed
= 0;
1009 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
1010 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
1011 /* skip invalid cache type */
1012 if (!is_cache_op_valid(type
, op
))
1015 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
1016 char *name
= event_cache_name(type
, op
, i
);
1018 if (event_glob
!= NULL
&& !strglobmatch(name
, event_glob
))
1021 printf(" %-50s [%s]\n", name
,
1022 event_type_descriptors
[PERF_TYPE_HW_CACHE
]);
1031 #define MAX_NAME_LEN 100
1034 * Print the help text for the event symbols:
1036 void print_events(const char *event_glob
)
1038 unsigned int i
, type
, prev_type
= -1, printed
= 0, ntypes_printed
= 0;
1039 struct event_symbol
*syms
= event_symbols
;
1040 char name
[MAX_NAME_LEN
];
1043 printf("List of pre-defined events (to be used in -e):\n");
1045 for (i
= 0; i
< ARRAY_SIZE(event_symbols
); i
++, syms
++) {
1048 if (type
!= prev_type
&& printed
) {
1054 if (event_glob
!= NULL
&&
1055 !(strglobmatch(syms
->symbol
, event_glob
) ||
1056 (syms
->alias
&& strglobmatch(syms
->alias
, event_glob
))))
1059 if (strlen(syms
->alias
))
1060 snprintf(name
, MAX_NAME_LEN
, "%s OR %s", syms
->symbol
, syms
->alias
);
1062 strncpy(name
, syms
->symbol
, MAX_NAME_LEN
);
1063 printf(" %-50s [%s]\n", name
,
1064 event_type_descriptors
[type
]);
1070 if (ntypes_printed
) {
1074 print_hwcache_events(event_glob
);
1076 if (event_glob
!= NULL
)
1080 printf(" %-50s [%s]\n",
1081 "rNNN (see 'perf list --help' on how to encode it)",
1082 event_type_descriptors
[PERF_TYPE_RAW
]);
1085 printf(" %-50s [%s]\n",
1086 "mem:<addr>[:access]",
1087 event_type_descriptors
[PERF_TYPE_BREAKPOINT
]);
1090 print_tracepoint_events(NULL
, NULL
);