• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __PERF_SESSION_H
2 #define __PERF_SESSION_H
3 
4 #include "hist.h"
5 #include "event.h"
6 #include "header.h"
7 #include "symbol.h"
8 #include "thread.h"
9 /* ANDROID_CHANGE_BEGIN */
10 #if 0
11 #include <linux/rbtree.h>
12 #include "../../../include/linux/perf_event.h"
13 #else
14 #include "include/linux/rbtree.h"
15 #include "include/linux/added/perf_event.h"
16 #endif
17 /* ANDROID_CHANGE_END */
18 
19 struct sample_queue;
20 struct ip_callchain;
21 struct thread;
22 
23 struct ordered_samples {
24 	u64			last_flush;
25 	u64			next_flush;
26 	u64			max_timestamp;
27 	struct list_head	samples;
28 	struct list_head	sample_cache;
29 	struct list_head	to_free;
30 	struct sample_queue	*sample_buffer;
31 	struct sample_queue	*last_sample;
32 	int			sample_buffer_idx;
33 };
34 
35 struct perf_session {
36 	struct perf_header	header;
37 	unsigned long		size;
38 	unsigned long		mmap_window;
39 	struct rb_root		threads;
40 	struct list_head	dead_threads;
41 	struct thread		*last_match;
42 	struct machine		host_machine;
43 	struct rb_root		machines;
44 	struct perf_evlist	*evlist;
45 	/*
46 	 * FIXME: Need to split this up further, we need global
47 	 *	  stats + per event stats. 'perf diff' also needs
48 	 *	  to properly support multiple events in a single
49 	 *	  perf.data file.
50 	 */
51 	struct hists		hists;
52 	u64			sample_type;
53 	int			sample_size;
54 	int			fd;
55 	bool			fd_pipe;
56 	bool			repipe;
57 	bool			sample_id_all;
58 	u16			id_hdr_size;
59 	int			cwdlen;
60 	char			*cwd;
61 	struct ordered_samples	ordered_samples;
62 	struct callchain_cursor	callchain_cursor;
63 	char			filename[0];
64 };
65 
66 struct perf_evsel;
67 struct perf_event_ops;
68 
69 typedef int (*event_sample)(union perf_event *event, struct perf_sample *sample,
70 			    struct perf_evsel *evsel, struct perf_session *session);
71 typedef int (*event_op)(union perf_event *self, struct perf_sample *sample,
72 			struct perf_session *session);
73 typedef int (*event_synth_op)(union perf_event *self,
74 			      struct perf_session *session);
75 typedef int (*event_op2)(union perf_event *self, struct perf_session *session,
76 			 struct perf_event_ops *ops);
77 
78 struct perf_event_ops {
79 	event_sample	sample;
80 	event_op	mmap,
81 			comm,
82 			fork,
83 			exit,
84 			lost,
85 			read,
86 			throttle,
87 			unthrottle;
88 	event_synth_op	attr,
89 			event_type,
90 			tracing_data,
91 			build_id;
92 	event_op2	finished_round;
93 	bool		ordered_samples;
94 	bool		ordering_requires_timestamps;
95 };
96 
97 struct perf_session *perf_session__new(const char *filename, int mode,
98 				       bool force, bool repipe,
99 				       struct perf_event_ops *ops);
100 void perf_session__delete(struct perf_session *self);
101 
102 void perf_event_header__bswap(struct perf_event_header *self);
103 
104 int __perf_session__process_events(struct perf_session *self,
105 				   u64 data_offset, u64 data_size, u64 size,
106 				   struct perf_event_ops *ops);
107 int perf_session__process_events(struct perf_session *self,
108 				 struct perf_event_ops *event_ops);
109 
110 int perf_session__resolve_callchain(struct perf_session *self,
111 				    struct thread *thread,
112 				    struct ip_callchain *chain,
113 				    struct symbol **parent);
114 
115 bool perf_session__has_traces(struct perf_session *self, const char *msg);
116 
117 int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
118 					     const char *symbol_name,
119 					     u64 addr);
120 
121 void mem_bswap_64(void *src, int byte_size);
122 void perf_event__attr_swap(struct perf_event_attr *attr);
123 
124 int perf_session__create_kernel_maps(struct perf_session *self);
125 
126 void perf_session__update_sample_type(struct perf_session *self);
127 void perf_session__remove_thread(struct perf_session *self, struct thread *th);
128 
129 static inline
perf_session__find_host_machine(struct perf_session * self)130 struct machine *perf_session__find_host_machine(struct perf_session *self)
131 {
132 	return &self->host_machine;
133 }
134 
135 static inline
perf_session__find_machine(struct perf_session * self,pid_t pid)136 struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
137 {
138 	if (pid == HOST_KERNEL_ID)
139 		return &self->host_machine;
140 	return machines__find(&self->machines, pid);
141 }
142 
143 static inline
perf_session__findnew_machine(struct perf_session * self,pid_t pid)144 struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
145 {
146 	if (pid == HOST_KERNEL_ID)
147 		return &self->host_machine;
148 	return machines__findnew(&self->machines, pid);
149 }
150 
151 static inline
perf_session__process_machines(struct perf_session * self,machine__process_t process)152 void perf_session__process_machines(struct perf_session *self,
153 				    machine__process_t process)
154 {
155 	process(&self->host_machine, self);
156 	return machines__process(&self->machines, process, self);
157 }
158 
159 size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
160 
161 size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
162 					  FILE *fp, bool with_hits);
163 
164 size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
165 
perf_session__parse_sample(struct perf_session * session,const union perf_event * event,struct perf_sample * sample)166 static inline int perf_session__parse_sample(struct perf_session *session,
167 					     const union perf_event *event,
168 					     struct perf_sample *sample)
169 {
170 	return perf_event__parse_sample(event, session->sample_type,
171 					session->sample_size,
172 					session->sample_id_all, sample);
173 }
174 
175 struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
176 					    unsigned int type);
177 
178 void perf_session__print_symbols(union perf_event *event,
179 				 struct perf_sample *sample,
180 				 struct perf_session *session);
181 
182 #endif /* __PERF_SESSION_H */
183