xref: /openbmc/linux/tools/perf/util/evlist.h (revision 95e9fd10)
1 #ifndef __PERF_EVLIST_H
2 #define __PERF_EVLIST_H 1
3 
4 #include <linux/list.h>
5 #include <stdio.h>
6 #include "../perf.h"
7 #include "event.h"
8 #include "util.h"
9 #include <unistd.h>
10 
11 struct pollfd;
12 struct thread_map;
13 struct cpu_map;
14 struct perf_record_opts;
15 
16 #define PERF_EVLIST__HLIST_BITS 8
17 #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
18 
19 struct perf_evlist {
20 	struct list_head entries;
21 	struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
22 	int		 nr_entries;
23 	int		 nr_fds;
24 	int		 nr_mmaps;
25 	int		 mmap_len;
26 	struct {
27 		int	cork_fd;
28 		pid_t	pid;
29 	} workload;
30 	bool		 overwrite;
31 	union perf_event event_copy;
32 	struct perf_mmap *mmap;
33 	struct pollfd	 *pollfd;
34 	struct thread_map *threads;
35 	struct cpu_map	  *cpus;
36 	struct perf_evsel *selected;
37 };
38 
39 struct perf_evsel_str_handler {
40 	const char *name;
41 	void	   *handler;
42 };
43 
44 struct perf_evsel;
45 
46 struct perf_evlist *perf_evlist__new(struct cpu_map *cpus,
47 				     struct thread_map *threads);
48 void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus,
49 		       struct thread_map *threads);
50 void perf_evlist__exit(struct perf_evlist *evlist);
51 void perf_evlist__delete(struct perf_evlist *evlist);
52 
53 void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
54 int perf_evlist__add_default(struct perf_evlist *evlist);
55 int perf_evlist__add_attrs(struct perf_evlist *evlist,
56 			   struct perf_event_attr *attrs, size_t nr_attrs);
57 int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
58 				     struct perf_event_attr *attrs, size_t nr_attrs);
59 int perf_evlist__add_tracepoints(struct perf_evlist *evlist,
60 				 const char *tracepoints[], size_t nr_tracepoints);
61 int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist,
62 					  const struct perf_evsel_str_handler *assocs,
63 					  size_t nr_assocs);
64 
65 #define perf_evlist__add_attrs_array(evlist, array) \
66 	perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array))
67 #define perf_evlist__add_default_attrs(evlist, array) \
68 	__perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
69 
70 #define perf_evlist__add_tracepoints_array(evlist, array) \
71 	perf_evlist__add_tracepoints(evlist, array, ARRAY_SIZE(array))
72 
73 #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \
74 	perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
75 
76 struct perf_evsel *
77 perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
78 
79 void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
80 			 int cpu, int thread, u64 id);
81 
82 void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
83 
84 struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
85 
86 union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx);
87 
88 int perf_evlist__open(struct perf_evlist *evlist, bool group);
89 
90 void perf_evlist__config_attrs(struct perf_evlist *evlist,
91 			       struct perf_record_opts *opts);
92 
93 int perf_evlist__prepare_workload(struct perf_evlist *evlist,
94 				  struct perf_record_opts *opts,
95 				  const char *argv[]);
96 int perf_evlist__start_workload(struct perf_evlist *evlist);
97 
98 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
99 		      bool overwrite);
100 void perf_evlist__munmap(struct perf_evlist *evlist);
101 
102 void perf_evlist__disable(struct perf_evlist *evlist);
103 void perf_evlist__enable(struct perf_evlist *evlist);
104 
105 void perf_evlist__set_selected(struct perf_evlist *evlist,
106 			       struct perf_evsel *evsel);
107 
108 static inline void perf_evlist__set_maps(struct perf_evlist *evlist,
109 					 struct cpu_map *cpus,
110 					 struct thread_map *threads)
111 {
112 	evlist->cpus	= cpus;
113 	evlist->threads	= threads;
114 }
115 
116 int perf_evlist__create_maps(struct perf_evlist *evlist,
117 			     struct perf_target *target);
118 void perf_evlist__delete_maps(struct perf_evlist *evlist);
119 int perf_evlist__set_filters(struct perf_evlist *evlist);
120 
121 u64 perf_evlist__sample_type(const struct perf_evlist *evlist);
122 bool perf_evlist__sample_id_all(const const struct perf_evlist *evlist);
123 u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
124 
125 int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event,
126 			      struct perf_sample *sample, bool swapped);
127 
128 bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
129 bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
130 
131 void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
132 				   struct list_head *list,
133 				   int nr_entries);
134 
135 #endif /* __PERF_EVLIST_H */
136