1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Builtin evlist command: Show the list of event selectors present 4 * in a perf.data file. 5 */ 6 #include "builtin.h" 7 8 #include <linux/list.h> 9 10 #include "util/evlist.h" 11 #include "util/evsel.h" 12 #include "util/evsel_fprintf.h" 13 #include "util/parse-events.h" 14 #include <subcmd/parse-options.h> 15 #include "util/session.h" 16 #include "util/data.h" 17 #include "util/debug.h" 18 #include <linux/err.h> 19 #include "util/tool.h" 20 #include "util/util.h" 21 22 static int process_header_feature(const struct perf_tool *tool __maybe_unused, 23 struct perf_session *session __maybe_unused, 24 union perf_event *event __maybe_unused) 25 { 26 session_done = 1; 27 return 0; 28 } 29 30 static int __cmd_evlist(const char *file_name, struct perf_attr_details *details) 31 { 32 struct perf_session *session; 33 struct evsel *pos; 34 struct perf_data data = { 35 .path = file_name, 36 .mode = PERF_DATA_MODE_READ, 37 .force = details->force, 38 }; 39 struct perf_tool tool; 40 bool has_tracepoint = false, has_group = false; 41 42 perf_tool__init(&tool, /*ordered_events=*/false); 43 /* only needed for pipe mode */ 44 tool.attr = perf_event__process_attr; 45 tool.feature = process_header_feature; 46 session = perf_session__new(&data, &tool); 47 if (IS_ERR(session)) 48 return PTR_ERR(session); 49 50 if (data.is_pipe) 51 perf_session__process_events(session); 52 53 evlist__for_each_entry(session->evlist, pos) { 54 evsel__fprintf(pos, details, stdout); 55 56 if (pos->core.attr.type == PERF_TYPE_TRACEPOINT) 57 has_tracepoint = true; 58 59 if (!evsel__is_group_leader(pos)) 60 has_group = true; 61 } 62 63 if (has_tracepoint && !details->trace_fields) 64 printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n"); 65 66 if (has_group && !details->event_group) 67 printf("# Tip: use 'perf evlist -g' to show group information\n"); 68 69 perf_session__delete(session); 70 return 0; 71 } 72 73 int cmd_evlist(int argc, const char **argv) 74 { 75 struct perf_attr_details details = { .verbose = false, }; 76 const struct option options[] = { 77 OPT_STRING('i', "input", &input_name, "file", "Input file name"), 78 OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"), 79 OPT_BOOLEAN('v', "verbose", &details.verbose, 80 "Show all event attr details"), 81 OPT_BOOLEAN('g', "group", &details.event_group, 82 "Show event group information"), 83 OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"), 84 OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"), 85 OPT_END() 86 }; 87 const char * const evlist_usage[] = { 88 "perf evlist [<options>]", 89 NULL 90 }; 91 92 argc = parse_options(argc, argv, options, evlist_usage, 0); 93 if (argc) 94 usage_with_options(evlist_usage, options); 95 96 if (details.event_group && (details.verbose || details.freq)) { 97 usage_with_options_msg(evlist_usage, options, 98 "--group option is not compatible with other options\n"); 99 } 100 101 return __cmd_evlist(input_name, &details); 102 } 103