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