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