blob: 98e99280125191cf41baa4590016e3295e30d860 [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>
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030020
Feng Tang70cb4e92012-10-30 11:56:02 +080021static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030022{
23 struct perf_session *session;
Jiri Olsa32dcd022019-07-21 13:23:51 +020024 struct evsel *pos;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010025 struct perf_data data = {
Jiri Olsa2d4f2792019-02-21 10:41:30 +010026 .path = file_name,
Jiri Olsaeae8ad82017-01-23 22:25:41 +010027 .mode = PERF_DATA_MODE_READ,
28 .force = details->force,
Jiri Olsaf5fc14122013-10-15 16:27:32 +020029 };
Namhyung Kim775d8a12016-01-07 09:12:29 +090030 bool has_tracepoint = false;
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030031
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010032 session = perf_session__new(&data, 0, NULL);
Mamatha Inamdar6ef81c52019-08-22 12:50:49 +053033 if (IS_ERR(session))
34 return PTR_ERR(session);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030035
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -030036 evlist__for_each_entry(session->evlist, pos) {
Arnaldo Carvalho de Melo2dbfc942020-05-06 13:00:39 -030037 evsel__fprintf(pos, details, stdout);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030038
Jiri Olsa1fc632c2019-07-21 13:24:29 +020039 if (pos->core.attr.type == PERF_TYPE_TRACEPOINT)
Namhyung Kim775d8a12016-01-07 09:12:29 +090040 has_tracepoint = true;
41 }
42
43 if (has_tracepoint && !details->trace_fields)
44 printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
45
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030046 perf_session__delete(session);
47 return 0;
48}
49
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -030050int cmd_evlist(int argc, const char **argv)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030051{
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030052 struct perf_attr_details details = { .verbose = false, };
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030053 const struct option options[] = {
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030054 OPT_STRING('i', "input", &input_name, "file", "Input file name"),
55 OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
56 OPT_BOOLEAN('v', "verbose", &details.verbose,
57 "Show all event attr details"),
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030058 OPT_BOOLEAN('g', "group", &details.event_group,
Namhyung Kime6ab07d2013-01-22 18:09:47 +090059 "Show event group information"),
Yunlong Song9e3b6ec2015-04-02 21:47:10 +080060 OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
Namhyung Kim775d8a12016-01-07 09:12:29 +090061 OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030062 OPT_END()
63 };
64 const char * const evlist_usage[] = {
65 "perf evlist [<options>]",
66 NULL
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030067 };
68
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030069 argc = parse_options(argc, argv, options, evlist_usage, 0);
70 if (argc)
71 usage_with_options(evlist_usage, options);
72
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030073 if (details.event_group && (details.verbose || details.freq)) {
Namhyung Kimc7118362015-10-25 00:49:27 +090074 usage_with_options_msg(evlist_usage, options,
75 "--group option is not compatible with other options\n");
Namhyung Kime6ab07d2013-01-22 18:09:47 +090076 }
77
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030078 return __cmd_evlist(input_name, &details);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030079}