blob: 4617b32c9c978df5fca8c3ed93bf36a670bef9bc [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -03002/*
3 * Builtin evlist command: Show the list of event selectors present
4 * in a perf.data file.
5 */
6#include "builtin.h"
7
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -03008#include <linux/list.h>
9
10#include "perf.h"
11#include "util/evlist.h"
12#include "util/evsel.h"
Arnaldo Carvalho de Meloca125272019-09-24 15:41:51 -030013#include "util/evsel_fprintf.h"
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030014#include "util/parse-events.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060015#include <subcmd/parse-options.h>
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030016#include "util/session.h"
Jiri Olsaf5fc14122013-10-15 16:27:32 +020017#include "util/data.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +020018#include "util/debug.h"
Mamatha Inamdar6ef81c52019-08-22 12:50:49 +053019#include <linux/err.h>
Namhyung Kim96aea4d2020-12-10 15:13:02 +090020#include "util/tool.h"
21
22static 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}
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030028
Feng Tang70cb4e92012-10-30 11:56:02 +080029static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030030{
31 struct perf_session *session;
Jiri Olsa32dcd022019-07-21 13:23:51 +020032 struct evsel *pos;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010033 struct perf_data data = {
Jiri Olsa2d4f2792019-02-21 10:41:30 +010034 .path = file_name,
Jiri Olsaeae8ad82017-01-23 22:25:41 +010035 .mode = PERF_DATA_MODE_READ,
36 .force = details->force,
Jiri Olsaf5fc14122013-10-15 16:27:32 +020037 };
Namhyung Kim96aea4d2020-12-10 15:13:02 +090038 struct perf_tool tool = {
39 /* only needed for pipe mode */
40 .attr = perf_event__process_attr,
41 .feature = process_header_feature,
42 };
Namhyung Kim775d8a12016-01-07 09:12:29 +090043 bool has_tracepoint = false;
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030044
Namhyung Kim96aea4d2020-12-10 15:13:02 +090045 session = perf_session__new(&data, 0, &tool);
Mamatha Inamdar6ef81c52019-08-22 12:50:49 +053046 if (IS_ERR(session))
47 return PTR_ERR(session);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030048
Namhyung Kim96aea4d2020-12-10 15:13:02 +090049 if (data.is_pipe)
50 perf_session__process_events(session);
51
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -030052 evlist__for_each_entry(session->evlist, pos) {
Arnaldo Carvalho de Melo2dbfc942020-05-06 13:00:39 -030053 evsel__fprintf(pos, details, stdout);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030054
Jiri Olsa1fc632c2019-07-21 13:24:29 +020055 if (pos->core.attr.type == PERF_TYPE_TRACEPOINT)
Namhyung Kim775d8a12016-01-07 09:12:29 +090056 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
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030062 perf_session__delete(session);
63 return 0;
64}
65
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -030066int cmd_evlist(int argc, const char **argv)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030067{
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030068 struct perf_attr_details details = { .verbose = false, };
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030069 const struct option options[] = {
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030070 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"),
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030074 OPT_BOOLEAN('g', "group", &details.event_group,
Namhyung Kime6ab07d2013-01-22 18:09:47 +090075 "Show event group information"),
Yunlong Song9e3b6ec2015-04-02 21:47:10 +080076 OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
Namhyung Kim775d8a12016-01-07 09:12:29 +090077 OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030078 OPT_END()
79 };
80 const char * const evlist_usage[] = {
81 "perf evlist [<options>]",
82 NULL
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030083 };
84
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030085 argc = parse_options(argc, argv, options, evlist_usage, 0);
86 if (argc)
87 usage_with_options(evlist_usage, options);
88
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030089 if (details.event_group && (details.verbose || details.freq)) {
Namhyung Kimc7118362015-10-25 00:49:27 +090090 usage_with_options_msg(evlist_usage, options,
91 "--group option is not compatible with other options\n");
Namhyung Kime6ab07d2013-01-22 18:09:47 +090092 }
93
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030094 return __cmd_evlist(input_name, &details);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030095}