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#include <linux/rbtree.h> 10#include "../../../include/linux/perf_event.h" 11 12struct sample_queue; 13struct ip_callchain; 14struct thread; 15 16struct ordered_samples { 17 u64 last_flush; 18 u64 next_flush; 19 u64 max_timestamp; 20 struct list_head samples_head; 21 struct sample_queue *last_inserted; 22}; 23 24struct perf_session { 25 struct perf_header header; 26 unsigned long size; 27 unsigned long mmap_window; 28 struct rb_root threads; 29 struct list_head dead_threads; 30 struct thread *last_match; 31 struct machine host_machine; 32 struct rb_root machines; 33 struct rb_root hists_tree; 34 struct hists hists; 35 u64 sample_type; 36 int fd; 37 bool fd_pipe; 38 bool repipe; 39 int cwdlen; 40 char *cwd; 41 struct ordered_samples ordered_samples; 42 char filename[0]; 43}; 44 45struct perf_event_ops; 46 47typedef int (*event_op)(event_t *self, struct perf_session *session); 48typedef int (*event_op2)(event_t *self, struct perf_session *session, 49 struct perf_event_ops *ops); 50 51struct perf_event_ops { 52 event_op sample, 53 mmap, 54 comm, 55 fork, 56 exit, 57 lost, 58 read, 59 throttle, 60 unthrottle, 61 attr, 62 event_type, 63 tracing_data, 64 build_id; 65 event_op2 finished_round; 66 bool ordered_samples; 67}; 68 69struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe); 70void perf_session__delete(struct perf_session *self); 71 72void perf_event_header__bswap(struct perf_event_header *self); 73 74int __perf_session__process_events(struct perf_session *self, 75 u64 data_offset, u64 data_size, u64 size, 76 struct perf_event_ops *ops); 77int perf_session__process_events(struct perf_session *self, 78 struct perf_event_ops *event_ops); 79 80struct map_symbol *perf_session__resolve_callchain(struct perf_session *self, 81 struct thread *thread, 82 struct ip_callchain *chain, 83 struct symbol **parent); 84 85bool perf_session__has_traces(struct perf_session *self, const char *msg); 86 87int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps, 88 const char *symbol_name, 89 u64 addr); 90 91void mem_bswap_64(void *src, int byte_size); 92 93int perf_session__create_kernel_maps(struct perf_session *self); 94 95int do_read(int fd, void *buf, size_t size); 96void perf_session__update_sample_type(struct perf_session *self); 97void perf_session__remove_thread(struct perf_session *self, struct thread *th); 98 99static inline 100struct machine *perf_session__find_host_machine(struct perf_session *self) 101{ 102 return &self->host_machine; 103} 104 105static inline 106struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid) 107{ 108 if (pid == HOST_KERNEL_ID) 109 return &self->host_machine; 110 return machines__find(&self->machines, pid); 111} 112 113static inline 114struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid) 115{ 116 if (pid == HOST_KERNEL_ID) 117 return &self->host_machine; 118 return machines__findnew(&self->machines, pid); 119} 120 121static inline 122void perf_session__process_machines(struct perf_session *self, 123 machine__process_t process) 124{ 125 process(&self->host_machine, self); 126 return machines__process(&self->machines, process, self); 127} 128 129size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp); 130 131size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, 132 FILE *fp, bool with_hits); 133 134static inline 135size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp) 136{ 137 return hists__fprintf_nr_events(&self->hists, fp); 138} 139#endif /* __PERF_SESSION_H */ 140