^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __PERF_SESSION_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __PERF_SESSION_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "trace-event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "header.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "machine.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "data.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "ordered-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "util/compress.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct ip_callchain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct symbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct auxtrace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct itrace_synth_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct perf_session {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct perf_header header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct machines machines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct evlist *evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct auxtrace *auxtrace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct itrace_synth_opts *itrace_synth_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct list_head auxtrace_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct trace_event tevent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct perf_record_time_conv time_conv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) bool repipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) bool one_mmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void *one_mmap_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u64 one_mmap_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct ordered_events ordered_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct perf_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct perf_tool *tool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) u64 bytes_transferred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u64 bytes_compressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct zstd_data zstd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct decomp *decomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct decomp *decomp_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct decomp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct decomp *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u64 file_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) size_t mmap_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u64 head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) char data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct perf_tool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct perf_session *perf_session__new(struct perf_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) bool repipe, struct perf_tool *tool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void perf_session__delete(struct perf_session *session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) void perf_event_header__bswap(struct perf_event_header *hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int perf_session__peek_event(struct perf_session *session, off_t file_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void *buf, size_t buf_sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) union perf_event **event_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct perf_sample *sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) typedef int (*peek_events_cb_t)(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) union perf_event *event, u64 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int perf_session__peek_events(struct perf_session *session, u64 offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u64 size, peek_events_cb_t cb, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int perf_session__process_events(struct perf_session *session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int perf_session__queue_event(struct perf_session *s, union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u64 timestamp, u64 file_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) void perf_tool__fill_defaults(struct perf_tool *tool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int perf_session__resolve_callchain(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct thread *thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct ip_callchain *chain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct symbol **parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) bool perf_session__has_traces(struct perf_session *session, const char *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void perf_event__attr_swap(struct perf_event_attr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int perf_session__create_kernel_maps(struct perf_session *session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) void perf_session__set_id_hdr_size(struct perf_session *session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct machine *perf_session__find_machine(struct perf_session *session, pid_t pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return machines__find(&session->machines, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct machine *perf_session__findnew_machine(struct perf_session *session, pid_t pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return machines__findnew(&session->machines, pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int perf_session__register_idle_thread(struct perf_session *session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) size_t perf_session__fprintf(struct perf_session *session, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) bool (fn)(struct dso *dso, int parm), int parm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct evsel *perf_session__find_first_evtype(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int perf_session__cpu_bitmap(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) const char *cpu_list, unsigned long *cpu_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct evsel_str_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define perf_session__set_tracepoints_handlers(session, array) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) __evlist__set_tracepoints_handlers(session->evlist, array, ARRAY_SIZE(array))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) extern volatile int session_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define session_done() READ_ONCE(session_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int perf_session__deliver_synth_event(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct perf_sample *sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int perf_event__process_id_index(struct perf_session *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) union perf_event *event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #endif /* __PERF_SESSION_H */