blob: 294494e60e481a4fc35a98aab6317d2ffc131ca1 [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"
13#include "util/parse-events.h"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060014#include <subcmd/parse-options.h>
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030015#include "util/session.h"
Jiri Olsaf5fc14122013-10-15 16:27:32 +020016#include "util/data.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +020017#include "util/debug.h"
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030018
Feng Tang70cb4e92012-10-30 11:56:02 +080019static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030020{
21 struct perf_session *session;
Jiri Olsa32dcd022019-07-21 13:23:51 +020022 struct evsel *pos;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010023 struct perf_data data = {
Jiri Olsa2d4f2792019-02-21 10:41:30 +010024 .path = file_name,
Jiri Olsaeae8ad82017-01-23 22:25:41 +010025 .mode = PERF_DATA_MODE_READ,
26 .force = details->force,
Jiri Olsaf5fc14122013-10-15 16:27:32 +020027 };
Namhyung Kim775d8a12016-01-07 09:12:29 +090028 bool has_tracepoint = false;
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030029
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010030 session = perf_session__new(&data, 0, NULL);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030031 if (session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +090032 return -1;
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030033
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -030034 evlist__for_each_entry(session->evlist, pos) {
Arnaldo Carvalho de Melo0698aed2012-12-10 18:17:08 -030035 perf_evsel__fprintf(pos, details, stdout);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030036
Jiri Olsa1fc632c2019-07-21 13:24:29 +020037 if (pos->core.attr.type == PERF_TYPE_TRACEPOINT)
Namhyung Kim775d8a12016-01-07 09:12:29 +090038 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
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030044 perf_session__delete(session);
45 return 0;
46}
47
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -030048int cmd_evlist(int argc, const char **argv)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030049{
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030050 struct perf_attr_details details = { .verbose = false, };
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030051 const struct option options[] = {
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030052 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"),
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030056 OPT_BOOLEAN('g', "group", &details.event_group,
Namhyung Kime6ab07d2013-01-22 18:09:47 +090057 "Show event group information"),
Yunlong Song9e3b6ec2015-04-02 21:47:10 +080058 OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
Namhyung Kim775d8a12016-01-07 09:12:29 +090059 OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030060 OPT_END()
61 };
62 const char * const evlist_usage[] = {
63 "perf evlist [<options>]",
64 NULL
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030065 };
66
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030067 argc = parse_options(argc, argv, options, evlist_usage, 0);
68 if (argc)
69 usage_with_options(evlist_usage, options);
70
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030071 if (details.event_group && (details.verbose || details.freq)) {
Namhyung Kimc7118362015-10-25 00:49:27 +090072 usage_with_options_msg(evlist_usage, options,
73 "--group option is not compatible with other options\n");
Namhyung Kime6ab07d2013-01-22 18:09:47 +090074 }
75
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030076 return __cmd_evlist(input_name, &details);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030077}