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