0001
0002
0003
0004
0005
0006 #include "builtin.h"
0007
0008 #include <linux/list.h>
0009
0010 #include "perf.h"
0011 #include "util/evlist.h"
0012 #include "util/evsel.h"
0013 #include "util/evsel_fprintf.h"
0014 #include "util/parse-events.h"
0015 #include <subcmd/parse-options.h>
0016 #include "util/session.h"
0017 #include "util/data.h"
0018 #include "util/debug.h"
0019 #include <linux/err.h>
0020 #include "util/tool.h"
0021
0022 static int process_header_feature(struct perf_session *session __maybe_unused,
0023 union perf_event *event __maybe_unused)
0024 {
0025 session_done = 1;
0026 return 0;
0027 }
0028
0029 static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
0030 {
0031 struct perf_session *session;
0032 struct evsel *pos;
0033 struct perf_data data = {
0034 .path = file_name,
0035 .mode = PERF_DATA_MODE_READ,
0036 .force = details->force,
0037 };
0038 struct perf_tool tool = {
0039
0040 .attr = perf_event__process_attr,
0041 .feature = process_header_feature,
0042 };
0043 bool has_tracepoint = false;
0044
0045 session = perf_session__new(&data, &tool);
0046 if (IS_ERR(session))
0047 return PTR_ERR(session);
0048
0049 if (data.is_pipe)
0050 perf_session__process_events(session);
0051
0052 evlist__for_each_entry(session->evlist, pos) {
0053 evsel__fprintf(pos, details, stdout);
0054
0055 if (pos->core.attr.type == PERF_TYPE_TRACEPOINT)
0056 has_tracepoint = true;
0057 }
0058
0059 if (has_tracepoint && !details->trace_fields)
0060 printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
0061
0062 perf_session__delete(session);
0063 return 0;
0064 }
0065
0066 int cmd_evlist(int argc, const char **argv)
0067 {
0068 struct perf_attr_details details = { .verbose = false, };
0069 const struct option options[] = {
0070 OPT_STRING('i', "input", &input_name, "file", "Input file name"),
0071 OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
0072 OPT_BOOLEAN('v', "verbose", &details.verbose,
0073 "Show all event attr details"),
0074 OPT_BOOLEAN('g', "group", &details.event_group,
0075 "Show event group information"),
0076 OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
0077 OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
0078 OPT_END()
0079 };
0080 const char * const evlist_usage[] = {
0081 "perf evlist [<options>]",
0082 NULL
0083 };
0084
0085 argc = parse_options(argc, argv, options, evlist_usage, 0);
0086 if (argc)
0087 usage_with_options(evlist_usage, options);
0088
0089 if (details.event_group && (details.verbose || details.freq)) {
0090 usage_with_options_msg(evlist_usage, options,
0091 "--group option is not compatible with other options\n");
0092 }
0093
0094 return __cmd_evlist(input_name, &details);
0095 }