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 perf_session { 24 struct perf_header header; 25 struct machines machines; 26 struct perf_evlist *evlist; 27 struct auxtrace *auxtrace; 28 struct itrace_synth_opts *itrace_synth_opts; 29 struct list_head auxtrace_index; 30 struct trace_event tevent; 31 struct time_conv_event time_conv; 32 bool repipe; 33 bool one_mmap; 34 void *one_mmap_addr; 35 u64 one_mmap_offset; 36 struct ordered_events ordered_events; 37 struct perf_data *data; 38 struct perf_tool *tool; 39 u64 bytes_transferred; 40 u64 bytes_compressed; 41 struct zstd_data zstd_data; 42 struct decomp *decomp; 43 struct decomp *decomp_last; 44 }; 45 46 struct decomp { 47 struct decomp *next; 48 u64 file_pos; 49 u64 head; 50 size_t size; 51 char data[]; 52 }; 53 54 struct perf_tool; 55 56 struct perf_session *perf_session__new(struct perf_data *data, 57 bool repipe, struct perf_tool *tool); 58 void perf_session__delete(struct perf_session *session); 59 60 void perf_event_header__bswap(struct perf_event_header *hdr); 61 62 int perf_session__peek_event(struct perf_session *session, off_t file_offset, 63 void *buf, size_t buf_sz, 64 union perf_event **event_ptr, 65 struct perf_sample *sample); 66 67 int perf_session__process_events(struct perf_session *session); 68 69 int perf_session__queue_event(struct perf_session *s, union perf_event *event, 70 u64 timestamp, u64 file_offset); 71 72 void perf_tool__fill_defaults(struct perf_tool *tool); 73 74 int perf_session__resolve_callchain(struct perf_session *session, 75 struct perf_evsel *evsel, 76 struct thread *thread, 77 struct ip_callchain *chain, 78 struct symbol **parent); 79 80 bool perf_session__has_traces(struct perf_session *session, const char *msg); 81 82 void perf_event__attr_swap(struct perf_event_attr *attr); 83 84 int perf_session__create_kernel_maps(struct perf_session *session); 85 86 void perf_session__set_id_hdr_size(struct perf_session *session); 87 88 static inline 89 struct machine *perf_session__find_machine(struct perf_session *session, pid_t pid) 90 { 91 return machines__find(&session->machines, pid); 92 } 93 94 static inline 95 struct machine *perf_session__findnew_machine(struct perf_session *session, pid_t pid) 96 { 97 return machines__findnew(&session->machines, pid); 98 } 99 100 struct thread *perf_session__findnew(struct perf_session *session, pid_t pid); 101 int perf_session__register_idle_thread(struct perf_session *session); 102 103 size_t perf_session__fprintf(struct perf_session *session, FILE *fp); 104 105 size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp); 106 107 size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp, 108 bool (fn)(struct dso *dso, int parm), int parm); 109 110 size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp); 111 112 struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, 113 unsigned int type); 114 115 int perf_session__cpu_bitmap(struct perf_session *session, 116 const char *cpu_list, unsigned long *cpu_bitmap); 117 118 void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full); 119 120 struct perf_evsel_str_handler; 121 122 int __perf_session__set_tracepoints_handlers(struct perf_session *session, 123 const struct perf_evsel_str_handler *assocs, 124 size_t nr_assocs); 125 126 #define perf_session__set_tracepoints_handlers(session, array) \ 127 __perf_session__set_tracepoints_handlers(session, array, ARRAY_SIZE(array)) 128 129 extern volatile int session_done; 130 131 #define session_done() READ_ONCE(session_done) 132 133 int perf_session__deliver_synth_event(struct perf_session *session, 134 union perf_event *event, 135 struct perf_sample *sample); 136 137 int perf_event__process_id_index(struct perf_session *session, 138 union perf_event *event); 139 140 int perf_event__synthesize_id_index(struct perf_tool *tool, 141 perf_event__handler_t process, 142 struct perf_evlist *evlist, 143 struct machine *machine); 144 145 #endif /* __PERF_SESSION_H */ 146