1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_SESSION_H
3 #define __PERF_SESSION_H
4 
5 #include "trace-event.h"
6 #include "event.h"
7 #include "header.h"
8 #include "machine.h"
9 #include "data.h"
10 #include "ordered-events.h"
11 #include "util/compress.h"
12 #include <linux/kernel.h>
13 #include <linux/rbtree.h>
14 #include <linux/perf_event.h>
15 
16 struct ip_callchain;
17 struct symbol;
18 struct thread;
19 
20 struct auxtrace;
21 struct itrace_synth_opts;
22 
23 struct decomp_data {
24 	struct decomp	 *decomp;
25 	struct decomp	 *decomp_last;
26 	struct zstd_data *zstd_decomp;
27 };
28 
29 struct perf_session {
30 	struct perf_header	header;
31 	struct machines		machines;
32 	struct evlist	*evlist;
33 	struct auxtrace		*auxtrace;
34 	struct itrace_synth_opts *itrace_synth_opts;
35 	struct list_head	auxtrace_index;
36 	struct trace_event	tevent;
37 	struct perf_record_time_conv	time_conv;
38 	bool			repipe;
39 	bool			one_mmap;
40 	void			*one_mmap_addr;
41 	u64			one_mmap_offset;
42 	struct ordered_events	ordered_events;
43 	struct perf_data	*data;
44 	struct perf_tool	*tool;
45 	u64			bytes_transferred;
46 	u64			bytes_compressed;
47 	struct zstd_data	zstd_data;
48 	struct decomp_data	decomp_data;
49 	struct decomp_data	*active_decomp;
50 };
51 
52 struct decomp {
53 	struct decomp *next;
54 	u64 file_pos;
55 	const char *file_path;
56 	size_t mmap_len;
57 	u64 head;
58 	size_t size;
59 	char data[];
60 };
61 
62 struct perf_tool;
63 
64 struct perf_session *__perf_session__new(struct perf_data *data,
65 					 bool repipe, int repipe_fd,
66 					 struct perf_tool *tool);
67 
perf_session__new(struct perf_data * data,struct perf_tool * tool)68 static inline struct perf_session *perf_session__new(struct perf_data *data,
69 						     struct perf_tool *tool)
70 {
71 	return __perf_session__new(data, false, -1, tool);
72 }
73 
74 void perf_session__delete(struct perf_session *session);
75 
76 void perf_event_header__bswap(struct perf_event_header *hdr);
77 
78 int perf_session__peek_event(struct perf_session *session, off_t file_offset,
79 			     void *buf, size_t buf_sz,
80 			     union perf_event **event_ptr,
81 			     struct perf_sample *sample);
82 typedef int (*peek_events_cb_t)(struct perf_session *session,
83 				union perf_event *event, u64 offset,
84 				void *data);
85 int perf_session__peek_events(struct perf_session *session, u64 offset,
86 			      u64 size, peek_events_cb_t cb, void *data);
87 
88 int perf_session__process_events(struct perf_session *session);
89 
90 int perf_session__queue_event(struct perf_session *s, union perf_event *event,
91 			      u64 timestamp, u64 file_offset, const char *file_path);
92 
93 void perf_tool__fill_defaults(struct perf_tool *tool);
94 
95 int perf_session__resolve_callchain(struct perf_session *session,
96 				    struct evsel *evsel,
97 				    struct thread *thread,
98 				    struct ip_callchain *chain,
99 				    struct symbol **parent);
100 
101 bool perf_session__has_traces(struct perf_session *session, const char *msg);
102 
103 void perf_event__attr_swap(struct perf_event_attr *attr);
104 
105 int perf_session__create_kernel_maps(struct perf_session *session);
106 
107 void perf_session__set_id_hdr_size(struct perf_session *session);
108 
109 static inline
perf_session__find_machine(struct perf_session * session,pid_t pid)110 struct machine *perf_session__find_machine(struct perf_session *session, pid_t pid)
111 {
112 	return machines__find(&session->machines, pid);
113 }
114 
115 static inline
perf_session__findnew_machine(struct perf_session * session,pid_t pid)116 struct machine *perf_session__findnew_machine(struct perf_session *session, pid_t pid)
117 {
118 	return machines__findnew(&session->machines, pid);
119 }
120 
121 struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);
122 int perf_session__register_idle_thread(struct perf_session *session);
123 
124 size_t perf_session__fprintf(struct perf_session *session, FILE *fp);
125 
126 size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);
127 
128 size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp,
129 					  bool (fn)(struct dso *dso, int parm), int parm);
130 
131 size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp,
132 				       bool skip_empty);
133 
134 struct evsel *perf_session__find_first_evtype(struct perf_session *session,
135 					    unsigned int type);
136 
137 int perf_session__cpu_bitmap(struct perf_session *session,
138 			     const char *cpu_list, unsigned long *cpu_bitmap);
139 
140 void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
141 
142 struct evsel_str_handler;
143 
144 #define perf_session__set_tracepoints_handlers(session, array) \
145 	__evlist__set_tracepoints_handlers(session->evlist, array, ARRAY_SIZE(array))
146 
147 extern volatile int session_done;
148 
149 #define session_done()	READ_ONCE(session_done)
150 
151 int perf_session__deliver_synth_event(struct perf_session *session,
152 				      union perf_event *event,
153 				      struct perf_sample *sample);
154 
155 int perf_event__process_id_index(struct perf_session *session,
156 				 union perf_event *event);
157 
158 int perf_event__process_finished_round(struct perf_tool *tool,
159 				       union perf_event *event,
160 				       struct ordered_events *oe);
161 
162 #endif /* __PERF_SESSION_H */
163