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 "perf.h" 11 #include "util/evlist.h" 12 #include "util/evsel.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 19 static int __cmd_evlist(const char *file_name, struct perf_attr_details *details) 20 { 21 struct perf_session *session; 22 struct evsel *pos; 23 struct perf_data data = { 24 .path = file_name, 25 .mode = PERF_DATA_MODE_READ, 26 .force = details->force, 27 }; 28 bool has_tracepoint = false; 29 30 session = perf_session__new(&data, 0, NULL); 31 if (session == NULL) 32 return -1; 33 34 evlist__for_each_entry(session->evlist, pos) { 35 perf_evsel__fprintf(pos, details, stdout); 36 37 if (pos->core.attr.type == PERF_TYPE_TRACEPOINT) 38 has_tracepoint = true; 39 } 40 41 if (has_tracepoint && !details->trace_fields) 42 printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n"); 43 44 perf_session__delete(session); 45 return 0; 46 } 47 48 int cmd_evlist(int argc, const char **argv) 49 { 50 struct perf_attr_details details = { .verbose = false, }; 51 const struct option options[] = { 52 OPT_STRING('i', "input", &input_name, "file", "Input file name"), 53 OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"), 54 OPT_BOOLEAN('v', "verbose", &details.verbose, 55 "Show all event attr details"), 56 OPT_BOOLEAN('g', "group", &details.event_group, 57 "Show event group information"), 58 OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"), 59 OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"), 60 OPT_END() 61 }; 62 const char * const evlist_usage[] = { 63 "perf evlist [<options>]", 64 NULL 65 }; 66 67 argc = parse_options(argc, argv, options, evlist_usage, 0); 68 if (argc) 69 usage_with_options(evlist_usage, options); 70 71 if (details.event_group && (details.verbose || details.freq)) { 72 usage_with_options_msg(evlist_usage, options, 73 "--group option is not compatible with other options\n"); 74 } 75 76 return __cmd_evlist(input_name, &details); 77 } 78