aboutsummaryrefslogtreecommitdiff
path: root/tools/perf/builtin-evlist.c
blob: 0dd5a058f766e2e2b2ad7196af78bf3d7a81d563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Builtin evlist command: Show the list of event selectors present
 * in a perf.data file.
 */
#include "builtin.h"

#include "util/util.h"

#include <linux/list.h>

#include "perf.h"
#include "util/evlist.h"
#include "util/evsel.h"
#include "util/parse-events.h"
#include "util/parse-options.h"
#include "util/session.h"

struct perf_attr_details {
	bool freq;
	bool verbose;
};

static int comma_printf(bool *first, const char *fmt, ...)
{
	va_list args;
	int ret = 0;

	if (!*first) {
		ret += printf(",");
	} else {
		ret += printf(":");
		*first = false;
	}

	va_start(args, fmt);
	ret += vprintf(fmt, args);
	va_end(args);
	return ret;
}

static int __if_print(bool *first, const char *field, u64 value)
{
	if (value == 0)
		return 0;

	return comma_printf(first, " %s: %" PRIu64, field, value);
}

#define if_print(field) __if_print(&first, #field, pos->attr.field)

static int __cmd_evlist(const char *input_name, struct perf_attr_details *details)
{
	struct perf_session *session;
	struct perf_evsel *pos;

	session = perf_session__new(input_name, O_RDONLY, 0, false, NULL);
	if (session == NULL)
		return -ENOMEM;

	list_for_each_entry(pos, &session->evlist->entries, node) {
		bool first = true;

		printf("%s", perf_evsel__name(pos));

		if (details->verbose || details->freq) {
			comma_printf(&first, " sample_freq=%" PRIu64,
				     (u64)pos->attr.sample_freq);
		}

		if (details->verbose) {
			if_print(type);
			if_print(config);
			if_print(config1);
			if_print(config2);
			if_print(size);
			if_print(sample_type);
			if_print(read_format);
			if_print(disabled);
			if_print(inherit);
			if_print(pinned);
			if_print(exclusive);
			if_print(exclude_user);
			if_print(exclude_kernel);
			if_print(exclude_hv);
			if_print(exclude_idle);
			if_print(mmap);
			if_print(comm);
			if_print(freq);
			if_print(inherit_stat);
			if_print(enable_on_exec);
			if_print(task);
			if_print(watermark);
			if_print(precise_ip);
			if_print(mmap_data);
			if_print(sample_id_all);
			if_print(exclude_host);
			if_print(exclude_guest);
			if_print(__reserved_1);
			if_print(wakeup_events);
			if_print(bp_type);
			if_print(branch_sample_type);
		}

		putchar('\n');
	}

	perf_session__delete(session);
	return 0;
}

static const char * const evlist_usage[] = {
	"perf evlist [<options>]",
	NULL
};

int cmd_evlist(int argc, const char **argv, const char *prefix __used)
{
	struct perf_attr_details details = { .verbose = false, };
	const char *input_name = NULL;
	const struct option options[] = {
		OPT_STRING('i', "input", &input_name, "file",
			    "Input file name"),
		OPT_BOOLEAN('F', "freq", &details.freq,
			    "Show the sample frequency"),
		OPT_BOOLEAN('v', "verbose", &details.verbose,
			    "Show all event attr details"),
		OPT_END()
	};

	argc = parse_options(argc, argv, options, evlist_usage, 0);
	if (argc)
		usage_with_options(evlist_usage, options);

	return __cmd_evlist(input_name, &details);
}