1 #include "../../../include/linux/hw_breakpoint.h"
6 #include "parse-options.h"
7 #include "parse-events.h"
14 #include "parse-events-flex.h"
17 #define MAX_NAME_LEN 100
27 extern int parse_events_debug
;
29 int parse_events_parse(struct list_head
*list
, int *idx
);
31 #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
32 #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
34 static struct event_symbol event_symbols
[] = {
35 { CHW(CPU_CYCLES
), "cpu-cycles", "cycles" },
36 { CHW(STALLED_CYCLES_FRONTEND
), "stalled-cycles-frontend", "idle-cycles-frontend" },
37 { CHW(STALLED_CYCLES_BACKEND
), "stalled-cycles-backend", "idle-cycles-backend" },
38 { CHW(INSTRUCTIONS
), "instructions", "" },
39 { CHW(CACHE_REFERENCES
), "cache-references", "" },
40 { CHW(CACHE_MISSES
), "cache-misses", "" },
41 { CHW(BRANCH_INSTRUCTIONS
), "branch-instructions", "branches" },
42 { CHW(BRANCH_MISSES
), "branch-misses", "" },
43 { CHW(BUS_CYCLES
), "bus-cycles", "" },
44 { CHW(REF_CPU_CYCLES
), "ref-cycles", "" },
46 { CSW(CPU_CLOCK
), "cpu-clock", "" },
47 { CSW(TASK_CLOCK
), "task-clock", "" },
48 { CSW(PAGE_FAULTS
), "page-faults", "faults" },
49 { CSW(PAGE_FAULTS_MIN
), "minor-faults", "" },
50 { CSW(PAGE_FAULTS_MAJ
), "major-faults", "" },
51 { CSW(CONTEXT_SWITCHES
), "context-switches", "cs" },
52 { CSW(CPU_MIGRATIONS
), "cpu-migrations", "migrations" },
53 { CSW(ALIGNMENT_FAULTS
), "alignment-faults", "" },
54 { CSW(EMULATION_FAULTS
), "emulation-faults", "" },
57 #define __PERF_EVENT_FIELD(config, name) \
58 ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT)
60 #define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW)
61 #define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG)
62 #define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE)
63 #define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT)
65 static const char *sw_event_names
[PERF_COUNT_SW_MAX
] = {
79 static const char *hw_cache
[PERF_COUNT_HW_CACHE_MAX
][MAX_ALIASES
] = {
80 { "L1-dcache", "l1-d", "l1d", "L1-data", },
81 { "L1-icache", "l1-i", "l1i", "L1-instruction", },
83 { "dTLB", "d-tlb", "Data-TLB", },
84 { "iTLB", "i-tlb", "Instruction-TLB", },
85 { "branch", "branches", "bpu", "btb", "bpc", },
89 static const char *hw_cache_op
[PERF_COUNT_HW_CACHE_OP_MAX
][MAX_ALIASES
] = {
90 { "load", "loads", "read", },
91 { "store", "stores", "write", },
92 { "prefetch", "prefetches", "speculative-read", "speculative-load", },
95 static const char *hw_cache_result
[PERF_COUNT_HW_CACHE_RESULT_MAX
]
97 { "refs", "Reference", "ops", "access", },
98 { "misses", "miss", },
101 #define C(x) PERF_COUNT_HW_CACHE_##x
102 #define CACHE_READ (1 << C(OP_READ))
103 #define CACHE_WRITE (1 << C(OP_WRITE))
104 #define CACHE_PREFETCH (1 << C(OP_PREFETCH))
105 #define COP(x) (1 << x)
108 * cache operartion stat
109 * L1I : Read and prefetch only
110 * ITLB and BPU : Read-only
112 static unsigned long hw_cache_stat
[C(MAX
)] = {
113 [C(L1D
)] = (CACHE_READ
| CACHE_WRITE
| CACHE_PREFETCH
),
114 [C(L1I
)] = (CACHE_READ
| CACHE_PREFETCH
),
115 [C(LL
)] = (CACHE_READ
| CACHE_WRITE
| CACHE_PREFETCH
),
116 [C(DTLB
)] = (CACHE_READ
| CACHE_WRITE
| CACHE_PREFETCH
),
117 [C(ITLB
)] = (CACHE_READ
),
118 [C(BPU
)] = (CACHE_READ
),
119 [C(NODE
)] = (CACHE_READ
| CACHE_WRITE
| CACHE_PREFETCH
),
122 #define for_each_subsystem(sys_dir, sys_dirent, sys_next) \
123 while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
124 if (sys_dirent.d_type == DT_DIR && \
125 (strcmp(sys_dirent.d_name, ".")) && \
126 (strcmp(sys_dirent.d_name, "..")))
128 static int tp_event_has_id(struct dirent
*sys_dir
, struct dirent
*evt_dir
)
130 char evt_path
[MAXPATHLEN
];
133 snprintf(evt_path
, MAXPATHLEN
, "%s/%s/%s/id", tracing_events_path
,
134 sys_dir
->d_name
, evt_dir
->d_name
);
135 fd
= open(evt_path
, O_RDONLY
);
143 #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \
144 while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
145 if (evt_dirent.d_type == DT_DIR && \
146 (strcmp(evt_dirent.d_name, ".")) && \
147 (strcmp(evt_dirent.d_name, "..")) && \
148 (!tp_event_has_id(&sys_dirent, &evt_dirent)))
150 #define MAX_EVENT_LENGTH 512
153 struct tracepoint_path
*tracepoint_id_to_path(u64 config
)
155 struct tracepoint_path
*path
= NULL
;
156 DIR *sys_dir
, *evt_dir
;
157 struct dirent
*sys_next
, *evt_next
, sys_dirent
, evt_dirent
;
161 char evt_path
[MAXPATHLEN
];
162 char dir_path
[MAXPATHLEN
];
164 if (debugfs_valid_mountpoint(tracing_events_path
))
167 sys_dir
= opendir(tracing_events_path
);
171 for_each_subsystem(sys_dir
, sys_dirent
, sys_next
) {
173 snprintf(dir_path
, MAXPATHLEN
, "%s/%s", tracing_events_path
,
175 evt_dir
= opendir(dir_path
);
179 for_each_event(sys_dirent
, evt_dir
, evt_dirent
, evt_next
) {
181 snprintf(evt_path
, MAXPATHLEN
, "%s/%s/id", dir_path
,
183 fd
= open(evt_path
, O_RDONLY
);
186 if (read(fd
, id_buf
, sizeof(id_buf
)) < 0) {
195 path
= zalloc(sizeof(*path
));
196 path
->system
= malloc(MAX_EVENT_LENGTH
);
201 path
->name
= malloc(MAX_EVENT_LENGTH
);
207 strncpy(path
->system
, sys_dirent
.d_name
,
209 strncpy(path
->name
, evt_dirent
.d_name
,
221 #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
222 static const char *tracepoint_id_to_name(u64 config
)
224 static char buf
[TP_PATH_LEN
];
225 struct tracepoint_path
*path
;
227 path
= tracepoint_id_to_path(config
);
229 snprintf(buf
, TP_PATH_LEN
, "%s:%s", path
->system
, path
->name
);
234 snprintf(buf
, TP_PATH_LEN
, "%s:%s", "unknown", "unknown");
239 static int is_cache_op_valid(u8 cache_type
, u8 cache_op
)
241 if (hw_cache_stat
[cache_type
] & COP(cache_op
))
242 return 1; /* valid */
244 return 0; /* invalid */
247 static char *event_cache_name(u8 cache_type
, u8 cache_op
, u8 cache_result
)
249 static char name
[50];
252 sprintf(name
, "%s-%s-%s", hw_cache
[cache_type
][0],
253 hw_cache_op
[cache_op
][0],
254 hw_cache_result
[cache_result
][0]);
256 sprintf(name
, "%s-%s", hw_cache
[cache_type
][0],
257 hw_cache_op
[cache_op
][1]);
263 const char *event_type(int type
)
266 case PERF_TYPE_HARDWARE
:
269 case PERF_TYPE_SOFTWARE
:
272 case PERF_TYPE_TRACEPOINT
:
275 case PERF_TYPE_HW_CACHE
:
276 return "hardware-cache";
285 const char *event_name(struct perf_evsel
*evsel
)
287 u64 config
= evsel
->attr
.config
;
288 int type
= evsel
->attr
.type
;
290 if (type
== PERF_TYPE_RAW
|| type
== PERF_TYPE_HARDWARE
) {
292 * XXX minimal fix, see comment on perf_evsen__name, this static buffer
293 * will go away together with event_name in the next devel cycle.
296 perf_evsel__name(evsel
, bf
, sizeof(bf
));
303 return __event_name(type
, config
);
306 const char *__event_name(int type
, u64 config
)
310 if (type
== PERF_TYPE_RAW
) {
311 sprintf(buf
, "raw 0x%" PRIx64
, config
);
316 case PERF_TYPE_HARDWARE
:
317 return __perf_evsel__hw_name(config
);
319 case PERF_TYPE_HW_CACHE
: {
320 u8 cache_type
, cache_op
, cache_result
;
322 cache_type
= (config
>> 0) & 0xff;
323 if (cache_type
> PERF_COUNT_HW_CACHE_MAX
)
324 return "unknown-ext-hardware-cache-type";
326 cache_op
= (config
>> 8) & 0xff;
327 if (cache_op
> PERF_COUNT_HW_CACHE_OP_MAX
)
328 return "unknown-ext-hardware-cache-op";
330 cache_result
= (config
>> 16) & 0xff;
331 if (cache_result
> PERF_COUNT_HW_CACHE_RESULT_MAX
)
332 return "unknown-ext-hardware-cache-result";
334 if (!is_cache_op_valid(cache_type
, cache_op
))
335 return "invalid-cache";
337 return event_cache_name(cache_type
, cache_op
, cache_result
);
340 case PERF_TYPE_SOFTWARE
:
341 if (config
< PERF_COUNT_SW_MAX
&& sw_event_names
[config
])
342 return sw_event_names
[config
];
343 return "unknown-software";
345 case PERF_TYPE_TRACEPOINT
:
346 return tracepoint_id_to_name(config
);
355 static int add_event(struct list_head
**_list
, int *idx
,
356 struct perf_event_attr
*attr
, char *name
)
358 struct perf_evsel
*evsel
;
359 struct list_head
*list
= *_list
;
362 list
= malloc(sizeof(*list
));
365 INIT_LIST_HEAD(list
);
368 event_attr_init(attr
);
370 evsel
= perf_evsel__new(attr
, (*idx
)++);
376 evsel
->name
= strdup(name
);
377 list_add_tail(&evsel
->node
, list
);
382 static int parse_aliases(char *str
, const char *names
[][MAX_ALIASES
], int size
)
387 for (i
= 0; i
< size
; i
++) {
388 for (j
= 0; j
< MAX_ALIASES
&& names
[i
][j
]; j
++) {
389 n
= strlen(names
[i
][j
]);
390 if (n
> longest
&& !strncasecmp(str
, names
[i
][j
], n
))
400 int parse_events_add_cache(struct list_head
**list
, int *idx
,
401 char *type
, char *op_result1
, char *op_result2
)
403 struct perf_event_attr attr
;
404 char name
[MAX_NAME_LEN
];
405 int cache_type
= -1, cache_op
= -1, cache_result
= -1;
406 char *op_result
[2] = { op_result1
, op_result2
};
410 * No fallback - if we cannot get a clear cache type
413 cache_type
= parse_aliases(type
, hw_cache
,
414 PERF_COUNT_HW_CACHE_MAX
);
415 if (cache_type
== -1)
418 n
= snprintf(name
, MAX_NAME_LEN
, "%s", type
);
420 for (i
= 0; (i
< 2) && (op_result
[i
]); i
++) {
421 char *str
= op_result
[i
];
423 snprintf(name
+ n
, MAX_NAME_LEN
- n
, "-%s\n", str
);
425 if (cache_op
== -1) {
426 cache_op
= parse_aliases(str
, hw_cache_op
,
427 PERF_COUNT_HW_CACHE_OP_MAX
);
429 if (!is_cache_op_valid(cache_type
, cache_op
))
435 if (cache_result
== -1) {
436 cache_result
= parse_aliases(str
, hw_cache_result
,
437 PERF_COUNT_HW_CACHE_RESULT_MAX
);
438 if (cache_result
>= 0)
444 * Fall back to reads:
447 cache_op
= PERF_COUNT_HW_CACHE_OP_READ
;
450 * Fall back to accesses:
452 if (cache_result
== -1)
453 cache_result
= PERF_COUNT_HW_CACHE_RESULT_ACCESS
;
455 memset(&attr
, 0, sizeof(attr
));
456 attr
.config
= cache_type
| (cache_op
<< 8) | (cache_result
<< 16);
457 attr
.type
= PERF_TYPE_HW_CACHE
;
458 return add_event(list
, idx
, &attr
, name
);
461 static int add_tracepoint(struct list_head
**list
, int *idx
,
462 char *sys_name
, char *evt_name
)
464 struct perf_event_attr attr
;
465 char name
[MAX_NAME_LEN
];
466 char evt_path
[MAXPATHLEN
];
471 snprintf(evt_path
, MAXPATHLEN
, "%s/%s/%s/id", tracing_events_path
,
474 fd
= open(evt_path
, O_RDONLY
);
478 if (read(fd
, id_buf
, sizeof(id_buf
)) < 0) {
486 memset(&attr
, 0, sizeof(attr
));
488 attr
.type
= PERF_TYPE_TRACEPOINT
;
489 attr
.sample_type
|= PERF_SAMPLE_RAW
;
490 attr
.sample_type
|= PERF_SAMPLE_TIME
;
491 attr
.sample_type
|= PERF_SAMPLE_CPU
;
492 attr
.sample_period
= 1;
494 snprintf(name
, MAX_NAME_LEN
, "%s:%s", sys_name
, evt_name
);
495 return add_event(list
, idx
, &attr
, name
);
498 static int add_tracepoint_multi(struct list_head
**list
, int *idx
,
499 char *sys_name
, char *evt_name
)
501 char evt_path
[MAXPATHLEN
];
502 struct dirent
*evt_ent
;
506 snprintf(evt_path
, MAXPATHLEN
, "%s/%s", tracing_events_path
, sys_name
);
507 evt_dir
= opendir(evt_path
);
509 perror("Can't open event dir");
513 while (!ret
&& (evt_ent
= readdir(evt_dir
))) {
514 if (!strcmp(evt_ent
->d_name
, ".")
515 || !strcmp(evt_ent
->d_name
, "..")
516 || !strcmp(evt_ent
->d_name
, "enable")
517 || !strcmp(evt_ent
->d_name
, "filter"))
520 if (!strglobmatch(evt_ent
->d_name
, evt_name
))
523 ret
= add_tracepoint(list
, idx
, sys_name
, evt_ent
->d_name
);
529 int parse_events_add_tracepoint(struct list_head
**list
, int *idx
,
530 char *sys
, char *event
)
534 ret
= debugfs_valid_mountpoint(tracing_events_path
);
538 return strpbrk(event
, "*?") ?
539 add_tracepoint_multi(list
, idx
, sys
, event
) :
540 add_tracepoint(list
, idx
, sys
, event
);
544 parse_breakpoint_type(const char *type
, struct perf_event_attr
*attr
)
548 for (i
= 0; i
< 3; i
++) {
549 if (!type
|| !type
[i
])
554 attr
->bp_type
|= HW_BREAKPOINT_R
;
557 attr
->bp_type
|= HW_BREAKPOINT_W
;
560 attr
->bp_type
|= HW_BREAKPOINT_X
;
567 if (!attr
->bp_type
) /* Default */
568 attr
->bp_type
= HW_BREAKPOINT_R
| HW_BREAKPOINT_W
;
573 int parse_events_add_breakpoint(struct list_head
**list
, int *idx
,
574 void *ptr
, char *type
)
576 struct perf_event_attr attr
;
577 char name
[MAX_NAME_LEN
];
579 memset(&attr
, 0, sizeof(attr
));
580 attr
.bp_addr
= (unsigned long) ptr
;
582 if (parse_breakpoint_type(type
, &attr
))
586 * We should find a nice way to override the access length
587 * Provide some defaults for now
589 if (attr
.bp_type
== HW_BREAKPOINT_X
)
590 attr
.bp_len
= sizeof(long);
592 attr
.bp_len
= HW_BREAKPOINT_LEN_4
;
594 attr
.type
= PERF_TYPE_BREAKPOINT
;
596 snprintf(name
, MAX_NAME_LEN
, "mem:%p:%s", ptr
, type
? type
: "rw");
597 return add_event(list
, idx
, &attr
, name
);
600 static int config_term(struct perf_event_attr
*attr
,
601 struct parse_events__term
*term
)
603 #define CHECK_TYPE_VAL(type) \
605 if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \
609 switch (term
->type_term
) {
610 case PARSE_EVENTS__TERM_TYPE_CONFIG
:
612 attr
->config
= term
->val
.num
;
614 case PARSE_EVENTS__TERM_TYPE_CONFIG1
:
616 attr
->config1
= term
->val
.num
;
618 case PARSE_EVENTS__TERM_TYPE_CONFIG2
:
620 attr
->config2
= term
->val
.num
;
622 case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD
:
624 attr
->sample_period
= term
->val
.num
;
626 case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE
:
628 * TODO uncomment when the field is available
629 * attr->branch_sample_type = term->val.num;
632 case PARSE_EVENTS__TERM_TYPE_NAME
:
640 #undef CHECK_TYPE_VAL
643 static int config_attr(struct perf_event_attr
*attr
,
644 struct list_head
*head
, int fail
)
646 struct parse_events__term
*term
;
648 list_for_each_entry(term
, head
, list
)
649 if (config_term(attr
, term
) && fail
)
655 int parse_events_add_numeric(struct list_head
**list
, int *idx
,
656 unsigned long type
, unsigned long config
,
657 struct list_head
*head_config
)
659 struct perf_event_attr attr
;
661 memset(&attr
, 0, sizeof(attr
));
663 attr
.config
= config
;
666 config_attr(&attr
, head_config
, 1))
669 return add_event(list
, idx
, &attr
,
670 (char *) __event_name(type
, config
));
673 static int parse_events__is_name_term(struct parse_events__term
*term
)
675 return term
->type_term
== PARSE_EVENTS__TERM_TYPE_NAME
;
678 static char *pmu_event_name(struct perf_event_attr
*attr
,
679 struct list_head
*head_terms
)
681 struct parse_events__term
*term
;
683 list_for_each_entry(term
, head_terms
, list
)
684 if (parse_events__is_name_term(term
))
685 return term
->val
.str
;
687 return (char *) __event_name(PERF_TYPE_RAW
, attr
->config
);
690 int parse_events_add_pmu(struct list_head
**list
, int *idx
,
691 char *name
, struct list_head
*head_config
)
693 struct perf_event_attr attr
;
694 struct perf_pmu
*pmu
;
696 pmu
= perf_pmu__find(name
);
700 memset(&attr
, 0, sizeof(attr
));
703 * Configure hardcoded terms first, no need to check
704 * return value when called with fail == 0 ;)
706 config_attr(&attr
, head_config
, 0);
708 if (perf_pmu__config(pmu
, &attr
, head_config
))
711 return add_event(list
, idx
, &attr
,
712 pmu_event_name(&attr
, head_config
));
715 void parse_events_update_lists(struct list_head
*list_event
,
716 struct list_head
*list_all
)
719 * Called for single event definition. Update the
720 * 'all event' list, and reinit the 'signle event'
721 * list, for next event definition.
723 list_splice_tail(list_event
, list_all
);
727 int parse_events_modifier(struct list_head
*list
, char *str
)
729 struct perf_evsel
*evsel
;
730 int exclude
= 0, exclude_GH
= 0;
731 int eu
= 0, ek
= 0, eh
= 0, eH
= 0, eG
= 0, precise
= 0;
739 exclude
= eu
= ek
= eh
= 1;
741 } else if (*str
== 'k') {
743 exclude
= eu
= ek
= eh
= 1;
745 } else if (*str
== 'h') {
747 exclude
= eu
= ek
= eh
= 1;
749 } else if (*str
== 'G') {
751 exclude_GH
= eG
= eH
= 1;
753 } else if (*str
== 'H') {
755 exclude_GH
= eG
= eH
= 1;
757 } else if (*str
== 'p') {
768 * 0 - SAMPLE_IP can have arbitrary skid
769 * 1 - SAMPLE_IP must have constant skid
770 * 2 - SAMPLE_IP requested to have 0 skid
771 * 3 - SAMPLE_IP must have 0 skid
773 * See also PERF_RECORD_MISC_EXACT_IP
778 list_for_each_entry(evsel
, list
, node
) {
779 evsel
->attr
.exclude_user
= eu
;
780 evsel
->attr
.exclude_kernel
= ek
;
781 evsel
->attr
.exclude_hv
= eh
;
782 evsel
->attr
.precise_ip
= precise
;
783 evsel
->attr
.exclude_host
= eH
;
784 evsel
->attr
.exclude_guest
= eG
;
790 int parse_events(struct perf_evlist
*evlist
, const char *str
, int unset __used
)
794 YY_BUFFER_STATE buffer
;
795 int ret
, idx
= evlist
->nr_entries
;
797 buffer
= parse_events__scan_string(str
);
800 parse_events_debug
= 1;
802 ret
= parse_events_parse(&list
, &idx
);
804 parse_events__flush_buffer(buffer
);
805 parse_events__delete_buffer(buffer
);
806 parse_events_lex_destroy();
809 int entries
= idx
- evlist
->nr_entries
;
810 perf_evlist__splice_list_tail(evlist
, &list
, entries
);
815 * There are 2 users - builtin-record and builtin-test objects.
816 * Both call perf_evlist__delete in case of error, so we dont
819 fprintf(stderr
, "invalid or unsupported event: '%s'\n", str
);
820 fprintf(stderr
, "Run 'perf list' for a list of valid events\n");
824 int parse_events_option(const struct option
*opt
, const char *str
,
827 struct perf_evlist
*evlist
= *(struct perf_evlist
**)opt
->value
;
828 return parse_events(evlist
, str
, unset
);
831 int parse_filter(const struct option
*opt
, const char *str
,
834 struct perf_evlist
*evlist
= *(struct perf_evlist
**)opt
->value
;
835 struct perf_evsel
*last
= NULL
;
837 if (evlist
->nr_entries
> 0)
838 last
= list_entry(evlist
->entries
.prev
, struct perf_evsel
, node
);
840 if (last
== NULL
|| last
->attr
.type
!= PERF_TYPE_TRACEPOINT
) {
842 "-F option should follow a -e tracepoint option\n");
846 last
->filter
= strdup(str
);
847 if (last
->filter
== NULL
) {
848 fprintf(stderr
, "not enough memory to hold filter string\n");
855 static const char * const event_type_descriptors
[] = {
859 "Hardware cache event",
860 "Raw hardware event descriptor",
861 "Hardware breakpoint",
865 * Print the events from <debugfs_mount_point>/tracing/events
868 void print_tracepoint_events(const char *subsys_glob
, const char *event_glob
)
870 DIR *sys_dir
, *evt_dir
;
871 struct dirent
*sys_next
, *evt_next
, sys_dirent
, evt_dirent
;
872 char evt_path
[MAXPATHLEN
];
873 char dir_path
[MAXPATHLEN
];
875 if (debugfs_valid_mountpoint(tracing_events_path
))
878 sys_dir
= opendir(tracing_events_path
);
882 for_each_subsystem(sys_dir
, sys_dirent
, sys_next
) {
883 if (subsys_glob
!= NULL
&&
884 !strglobmatch(sys_dirent
.d_name
, subsys_glob
))
887 snprintf(dir_path
, MAXPATHLEN
, "%s/%s", tracing_events_path
,
889 evt_dir
= opendir(dir_path
);
893 for_each_event(sys_dirent
, evt_dir
, evt_dirent
, evt_next
) {
894 if (event_glob
!= NULL
&&
895 !strglobmatch(evt_dirent
.d_name
, event_glob
))
898 snprintf(evt_path
, MAXPATHLEN
, "%s:%s",
899 sys_dirent
.d_name
, evt_dirent
.d_name
);
900 printf(" %-50s [%s]\n", evt_path
,
901 event_type_descriptors
[PERF_TYPE_TRACEPOINT
]);
909 * Check whether event is in <debugfs_mount_point>/tracing/events
912 int is_valid_tracepoint(const char *event_string
)
914 DIR *sys_dir
, *evt_dir
;
915 struct dirent
*sys_next
, *evt_next
, sys_dirent
, evt_dirent
;
916 char evt_path
[MAXPATHLEN
];
917 char dir_path
[MAXPATHLEN
];
919 if (debugfs_valid_mountpoint(tracing_events_path
))
922 sys_dir
= opendir(tracing_events_path
);
926 for_each_subsystem(sys_dir
, sys_dirent
, sys_next
) {
928 snprintf(dir_path
, MAXPATHLEN
, "%s/%s", tracing_events_path
,
930 evt_dir
= opendir(dir_path
);
934 for_each_event(sys_dirent
, evt_dir
, evt_dirent
, evt_next
) {
935 snprintf(evt_path
, MAXPATHLEN
, "%s:%s",
936 sys_dirent
.d_name
, evt_dirent
.d_name
);
937 if (!strcmp(evt_path
, event_string
)) {
949 void print_events_type(u8 type
)
951 struct event_symbol
*syms
= event_symbols
;
955 for (i
= 0; i
< ARRAY_SIZE(event_symbols
); i
++, syms
++) {
956 if (type
!= syms
->type
)
959 if (strlen(syms
->alias
))
960 snprintf(name
, sizeof(name
), "%s OR %s",
961 syms
->symbol
, syms
->alias
);
963 snprintf(name
, sizeof(name
), "%s", syms
->symbol
);
965 printf(" %-50s [%s]\n", name
,
966 event_type_descriptors
[type
]);
970 int print_hwcache_events(const char *event_glob
)
972 unsigned int type
, op
, i
, printed
= 0;
974 for (type
= 0; type
< PERF_COUNT_HW_CACHE_MAX
; type
++) {
975 for (op
= 0; op
< PERF_COUNT_HW_CACHE_OP_MAX
; op
++) {
976 /* skip invalid cache type */
977 if (!is_cache_op_valid(type
, op
))
980 for (i
= 0; i
< PERF_COUNT_HW_CACHE_RESULT_MAX
; i
++) {
981 char *name
= event_cache_name(type
, op
, i
);
983 if (event_glob
!= NULL
&& !strglobmatch(name
, event_glob
))
986 printf(" %-50s [%s]\n", name
,
987 event_type_descriptors
[PERF_TYPE_HW_CACHE
]);
997 * Print the help text for the event symbols:
999 void print_events(const char *event_glob
)
1001 unsigned int i
, type
, prev_type
= -1, printed
= 0, ntypes_printed
= 0;
1002 struct event_symbol
*syms
= event_symbols
;
1003 char name
[MAX_NAME_LEN
];
1006 printf("List of pre-defined events (to be used in -e):\n");
1008 for (i
= 0; i
< ARRAY_SIZE(event_symbols
); i
++, syms
++) {
1011 if (type
!= prev_type
&& printed
) {
1017 if (event_glob
!= NULL
&&
1018 !(strglobmatch(syms
->symbol
, event_glob
) ||
1019 (syms
->alias
&& strglobmatch(syms
->alias
, event_glob
))))
1022 if (strlen(syms
->alias
))
1023 snprintf(name
, MAX_NAME_LEN
, "%s OR %s", syms
->symbol
, syms
->alias
);
1025 strncpy(name
, syms
->symbol
, MAX_NAME_LEN
);
1026 printf(" %-50s [%s]\n", name
,
1027 event_type_descriptors
[type
]);
1033 if (ntypes_printed
) {
1037 print_hwcache_events(event_glob
);
1039 if (event_glob
!= NULL
)
1043 printf(" %-50s [%s]\n",
1045 event_type_descriptors
[PERF_TYPE_RAW
]);
1046 printf(" %-50s [%s]\n",
1047 "cpu/t1=v1[,t2=v2,t3 ...]/modifier",
1048 event_type_descriptors
[PERF_TYPE_RAW
]);
1049 printf(" (see 'perf list --help' on how to encode it)\n");
1052 printf(" %-50s [%s]\n",
1053 "mem:<addr>[:access]",
1054 event_type_descriptors
[PERF_TYPE_BREAKPOINT
]);
1057 print_tracepoint_events(NULL
, NULL
);
1060 int parse_events__is_hardcoded_term(struct parse_events__term
*term
)
1062 return term
->type_term
!= PARSE_EVENTS__TERM_TYPE_USER
;
1065 static int new_term(struct parse_events__term
**_term
, int type_val
,
1066 int type_term
, char *config
,
1067 char *str
, long num
)
1069 struct parse_events__term
*term
;
1071 term
= zalloc(sizeof(*term
));
1075 INIT_LIST_HEAD(&term
->list
);
1076 term
->type_val
= type_val
;
1077 term
->type_term
= type_term
;
1078 term
->config
= config
;
1081 case PARSE_EVENTS__TERM_TYPE_NUM
:
1082 term
->val
.num
= num
;
1084 case PARSE_EVENTS__TERM_TYPE_STR
:
1085 term
->val
.str
= str
;
1095 int parse_events__term_num(struct parse_events__term
**term
,
1096 int type_term
, char *config
, long num
)
1098 return new_term(term
, PARSE_EVENTS__TERM_TYPE_NUM
, type_term
,
1102 int parse_events__term_str(struct parse_events__term
**term
,
1103 int type_term
, char *config
, char *str
)
1105 return new_term(term
, PARSE_EVENTS__TERM_TYPE_STR
, type_term
,
1109 void parse_events__free_terms(struct list_head
*terms
)
1111 struct parse_events__term
*term
, *h
;
1113 list_for_each_entry_safe(term
, h
, terms
, list
)