blob: 6d210e40d611b00b5a5292ccc76d5f2881a51ee5 [file] [log] [blame]
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -03001/*
2 * Builtin evlist command: Show the list of event selectors present
3 * in a perf.data file.
4 */
5#include "builtin.h"
6
7#include "util/util.h"
8
9#include <linux/list.h>
10
11#include "perf.h"
12#include "util/evlist.h"
13#include "util/evsel.h"
14#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 Olsaf5fc1412013-10-15 16:27:32 +020017#include "util/data.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +020018#include "util/debug.h"
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030019
Feng Tang70cb4e92012-10-30 11:56:02 +080020static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030021{
22 struct perf_session *session;
23 struct perf_evsel *pos;
Jiri Olsaf5fc1412013-10-15 16:27:32 +020024 struct perf_data_file file = {
25 .path = file_name,
26 .mode = PERF_DATA_MODE_READ,
Yunlong Song9e3b6ec2015-04-02 21:47:10 +080027 .force = details->force,
Jiri Olsaf5fc1412013-10-15 16:27:32 +020028 };
Namhyung Kim775d8a12016-01-07 09:12:29 +090029 bool has_tracepoint = false;
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030030
Jiri Olsaf5fc1412013-10-15 16:27:32 +020031 session = perf_session__new(&file, 0, NULL);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030032 if (session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +090033 return -1;
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030034
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -030035 evlist__for_each_entry(session->evlist, pos) {
Arnaldo Carvalho de Melo0698aed2012-12-10 18:17:08 -030036 perf_evsel__fprintf(pos, details, stdout);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030037
Namhyung Kim775d8a12016-01-07 09:12:29 +090038 if (pos->attr.type == PERF_TYPE_TRACEPOINT)
39 has_tracepoint = true;
40 }
41
42 if (has_tracepoint && !details->trace_fields)
43 printf("# Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events\n");
44
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030045 perf_session__delete(session);
46 return 0;
47}
48
Arnaldo Carvalho de Melob0ad8ea2017-03-27 11:47:20 -030049int cmd_evlist(int argc, const char **argv)
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030050{
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030051 struct perf_attr_details details = { .verbose = false, };
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030052 const struct option options[] = {
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030053 OPT_STRING('i', "input", &input_name, "file", "Input file name"),
54 OPT_BOOLEAN('F', "freq", &details.freq, "Show the sample frequency"),
55 OPT_BOOLEAN('v', "verbose", &details.verbose,
56 "Show all event attr details"),
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030057 OPT_BOOLEAN('g', "group", &details.event_group,
Namhyung Kime6ab07d2013-01-22 18:09:47 +090058 "Show event group information"),
Yunlong Song9e3b6ec2015-04-02 21:47:10 +080059 OPT_BOOLEAN('f', "force", &details.force, "don't complain, do it"),
Namhyung Kim775d8a12016-01-07 09:12:29 +090060 OPT_BOOLEAN(0, "trace-fields", &details.trace_fields, "Show tracepoint fields"),
Arnaldo Carvalho de Melo94d668d2012-10-01 15:20:58 -030061 OPT_END()
62 };
63 const char * const evlist_usage[] = {
64 "perf evlist [<options>]",
65 NULL
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030066 };
67
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030068 argc = parse_options(argc, argv, options, evlist_usage, 0);
69 if (argc)
70 usage_with_options(evlist_usage, options);
71
Arnaldo Carvalho de Meloe35ef3552013-02-06 17:20:02 -030072 if (details.event_group && (details.verbose || details.freq)) {
Namhyung Kimc7118362015-10-25 00:49:27 +090073 usage_with_options_msg(evlist_usage, options,
74 "--group option is not compatible with other options\n");
Namhyung Kime6ab07d2013-01-22 18:09:47 +090075 }
76
Arnaldo Carvalho de Melo26252ea2012-05-22 14:30:11 -030077 return __cmd_evlist(input_name, &details);
Arnaldo Carvalho de Melo43adec92011-03-15 11:04:13 -030078}