Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 2 | #ifndef __PERF_SESSION_H |
| 3 | #define __PERF_SESSION_H |
| 4 | |
Jiri Olsa | 29f5ffd | 2013-12-03 14:09:23 +0100 | [diff] [blame] | 5 | #include "trace-event.h" |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 6 | #include "event.h" |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 7 | #include "header.h" |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 8 | #include "machine.h" |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 9 | #include "data.h" |
Jiri Olsa | 5f86b80 | 2014-08-01 13:02:58 -0300 | [diff] [blame] | 10 | #include "ordered-events.h" |
Alexey Budankov | 5d7f411 | 2019-03-18 20:43:35 +0300 | [diff] [blame] | 11 | #include "util/compress.h" |
Arnaldo Carvalho de Melo | 877a7a1 | 2017-04-17 11:39:06 -0300 | [diff] [blame] | 12 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 13 | #include <linux/rbtree.h> |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 14 | #include <linux/perf_event.h> |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 15 | |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 16 | struct ip_callchain; |
Arnaldo Carvalho de Melo | e7ff892 | 2017-04-19 21:34:35 -0300 | [diff] [blame] | 17 | struct symbol; |
Arnaldo Carvalho de Melo | b3165f4 | 2009-12-13 19:50:28 -0200 | [diff] [blame] | 18 | struct thread; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 19 | |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 20 | struct auxtrace; |
Adrian Hunter | f6986c95 | 2015-04-09 18:53:49 +0300 | [diff] [blame] | 21 | struct itrace_synth_opts; |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 22 | |
Alexey Bayduraev | 3a3535e | 2021-10-13 12:06:36 +0300 | [diff] [blame] | 23 | struct decomp_data { |
| 24 | struct decomp *decomp; |
| 25 | struct decomp *decomp_last; |
| 26 | struct zstd_data *zstd_decomp; |
| 27 | }; |
| 28 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 29 | struct perf_session { |
| 30 | struct perf_header header; |
Arnaldo Carvalho de Melo | 876650e6 | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 31 | struct machines machines; |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 32 | struct evlist *evlist; |
Adrian Hunter | c446870 | 2015-04-09 18:53:48 +0300 | [diff] [blame] | 33 | struct auxtrace *auxtrace; |
Adrian Hunter | f6986c95 | 2015-04-09 18:53:49 +0300 | [diff] [blame] | 34 | struct itrace_synth_opts *itrace_synth_opts; |
Adrian Hunter | 99fa298 | 2015-04-30 17:37:25 +0300 | [diff] [blame] | 35 | struct list_head auxtrace_index; |
Jiri Olsa | 29f5ffd | 2013-12-03 14:09:23 +0100 | [diff] [blame] | 36 | struct trace_event tevent; |
Jiri Olsa | 7293237 | 2019-08-28 15:57:16 +0200 | [diff] [blame] | 37 | struct perf_record_time_conv time_conv; |
Tom Zanussi | 454c407 | 2010-05-01 01:41:20 -0500 | [diff] [blame] | 38 | bool repipe; |
Adrian Hunter | 919d86d | 2014-07-14 13:02:51 +0300 | [diff] [blame] | 39 | bool one_mmap; |
| 40 | void *one_mmap_addr; |
| 41 | u64 one_mmap_offset; |
Jiri Olsa | 37e39aa | 2014-07-06 14:23:03 +0200 | [diff] [blame] | 42 | struct ordered_events ordered_events; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 43 | struct perf_data *data; |
Arnaldo Carvalho de Melo | 9870d78 | 2015-03-31 12:48:16 -0300 | [diff] [blame] | 44 | struct perf_tool *tool; |
Alexey Budankov | d3c8c08 | 2019-03-18 20:41:02 +0300 | [diff] [blame] | 45 | u64 bytes_transferred; |
| 46 | u64 bytes_compressed; |
Alexey Budankov | 5d7f411 | 2019-03-18 20:43:35 +0300 | [diff] [blame] | 47 | struct zstd_data zstd_data; |
Alexey Bayduraev | 3a3535e | 2021-10-13 12:06:36 +0300 | [diff] [blame] | 48 | struct decomp_data decomp_data; |
| 49 | struct decomp_data *active_decomp; |
Alexey Budankov | cb62c6f | 2019-03-18 20:45:11 +0300 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct decomp { |
| 53 | struct decomp *next; |
| 54 | u64 file_pos; |
Alexey Budankov | 872c8ee | 2019-07-09 17:48:14 +0300 | [diff] [blame] | 55 | size_t mmap_len; |
Alexey Budankov | cb62c6f | 2019-03-18 20:45:11 +0300 | [diff] [blame] | 56 | u64 head; |
| 57 | size_t size; |
| 58 | char data[]; |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 59 | }; |
| 60 | |
Arnaldo Carvalho de Melo | 45694aa | 2011-11-28 08:30:20 -0200 | [diff] [blame] | 61 | struct perf_tool; |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 62 | |
Namhyung Kim | 2681bd8 | 2021-07-19 15:31:49 -0700 | [diff] [blame] | 63 | struct perf_session *__perf_session__new(struct perf_data *data, |
Namhyung Kim | 0ae0389 | 2021-07-19 15:31:50 -0700 | [diff] [blame] | 64 | bool repipe, int repipe_fd, |
Namhyung Kim | 2681bd8 | 2021-07-19 15:31:49 -0700 | [diff] [blame] | 65 | struct perf_tool *tool); |
| 66 | |
| 67 | static inline struct perf_session *perf_session__new(struct perf_data *data, |
| 68 | struct perf_tool *tool) |
| 69 | { |
Namhyung Kim | 0ae0389 | 2021-07-19 15:31:50 -0700 | [diff] [blame] | 70 | return __perf_session__new(data, false, -1, tool); |
Namhyung Kim | 2681bd8 | 2021-07-19 15:31:49 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Arnaldo Carvalho de Melo | 876650e6 | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 73 | void perf_session__delete(struct perf_session *session); |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 74 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 75 | void perf_event_header__bswap(struct perf_event_header *hdr); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 76 | |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 77 | int perf_session__peek_event(struct perf_session *session, off_t file_offset, |
| 78 | void *buf, size_t buf_sz, |
| 79 | union perf_event **event_ptr, |
| 80 | struct perf_sample *sample); |
Adrian Hunter | 103ed40 | 2019-11-15 14:42:20 +0200 | [diff] [blame] | 81 | typedef int (*peek_events_cb_t)(struct perf_session *session, |
| 82 | union perf_event *event, u64 offset, |
| 83 | void *data); |
| 84 | int perf_session__peek_events(struct perf_session *session, u64 offset, |
| 85 | u64 size, peek_events_cb_t cb, void *data); |
Adrian Hunter | 5a52f33 | 2014-07-31 09:00:57 +0300 | [diff] [blame] | 86 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 87 | int perf_session__process_events(struct perf_session *session); |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 88 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 89 | int perf_session__queue_event(struct perf_session *s, union perf_event *event, |
Jiri Olsa | dc83e13 | 2017-08-03 13:24:33 +0200 | [diff] [blame] | 90 | u64 timestamp, u64 file_offset); |
David Ahern | 9c50140 | 2013-08-02 14:05:41 -0600 | [diff] [blame] | 91 | |
| 92 | void perf_tool__fill_defaults(struct perf_tool *tool); |
| 93 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 94 | int perf_session__resolve_callchain(struct perf_session *session, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 95 | struct evsel *evsel, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 96 | struct thread *thread, |
| 97 | struct ip_callchain *chain, |
| 98 | struct symbol **parent); |
Arnaldo Carvalho de Melo | a328626 | 2009-12-14 14:22:59 -0200 | [diff] [blame] | 99 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 100 | bool perf_session__has_traces(struct perf_session *session, const char *msg); |
Arnaldo Carvalho de Melo | 2729559 | 2009-12-27 21:37:01 -0200 | [diff] [blame] | 101 | |
David Ahern | eda3913 | 2011-07-15 12:34:09 -0600 | [diff] [blame] | 102 | void perf_event__attr_swap(struct perf_event_attr *attr); |
Arnaldo Carvalho de Melo | ba21594 | 2010-01-14 12:23:10 -0200 | [diff] [blame] | 103 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 104 | int perf_session__create_kernel_maps(struct perf_session *session); |
Arnaldo Carvalho de Melo | f9224c5 | 2010-03-11 20:12:44 -0300 | [diff] [blame] | 105 | |
Arnaldo Carvalho de Melo | 7b56cce | 2012-08-01 19:31:00 -0300 | [diff] [blame] | 106 | void perf_session__set_id_hdr_size(struct perf_session *session); |
Tom Zanussi | 8dc5810 | 2010-04-01 23:59:15 -0500 | [diff] [blame] | 107 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 108 | static inline |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 109 | struct machine *perf_session__find_machine(struct perf_session *session, pid_t pid) |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 110 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 111 | return machines__find(&session->machines, pid); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static inline |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 115 | struct machine *perf_session__findnew_machine(struct perf_session *session, pid_t pid) |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 116 | { |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 117 | return machines__findnew(&session->machines, pid); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 118 | } |
| 119 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 120 | struct thread *perf_session__findnew(struct perf_session *session, pid_t pid); |
Masami Hiramatsu | 9d8b172 | 2015-12-09 11:11:23 +0900 | [diff] [blame] | 121 | int perf_session__register_idle_thread(struct perf_session *session); |
Namhyung Kim | c53d138 | 2015-09-30 10:45:26 +0900 | [diff] [blame] | 122 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 123 | size_t perf_session__fprintf(struct perf_session *session, FILE *fp); |
Arnaldo Carvalho de Melo | 743eb86 | 2011-11-28 07:56:39 -0200 | [diff] [blame] | 124 | |
Arnaldo Carvalho de Melo | 316c713 | 2013-11-05 15:32:36 -0300 | [diff] [blame] | 125 | size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp); |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 126 | |
Arnaldo Carvalho de Melo | 417c2ff | 2012-12-07 09:53:58 -0300 | [diff] [blame] | 127 | size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp, |
| 128 | bool (fn)(struct dso *dso, int parm), int parm); |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 129 | |
Namhyung Kim | 2775de0 | 2021-04-26 18:37:15 -0700 | [diff] [blame] | 130 | size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp, |
| 131 | bool skip_empty); |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 132 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 133 | struct evsel *perf_session__find_first_evtype(struct perf_session *session, |
David Ahern | 9cbdb70 | 2011-04-06 21:54:20 -0600 | [diff] [blame] | 134 | unsigned int type); |
| 135 | |
Anton Blanchard | 5d67be9 | 2011-07-04 21:57:50 +1000 | [diff] [blame] | 136 | int perf_session__cpu_bitmap(struct perf_session *session, |
| 137 | const char *cpu_list, unsigned long *cpu_bitmap); |
| 138 | |
Stephane Eranian | fbe96f2 | 2011-09-30 15:40:40 +0200 | [diff] [blame] | 139 | void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full); |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 140 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 141 | struct evsel_str_handler; |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 142 | |
Arnaldo Carvalho de Melo | da37896 | 2012-06-27 13:08:42 -0300 | [diff] [blame] | 143 | #define perf_session__set_tracepoints_handlers(session, array) \ |
Arnaldo Carvalho de Melo | c0e5347 | 2019-10-01 11:14:26 -0300 | [diff] [blame] | 144 | __evlist__set_tracepoints_handlers(session->evlist, array, ARRAY_SIZE(array)) |
Arnaldo Carvalho de Melo | 33e940a | 2013-09-17 16:34:28 -0300 | [diff] [blame] | 145 | |
| 146 | extern volatile int session_done; |
| 147 | |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 148 | #define session_done() READ_ONCE(session_done) |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 149 | |
Adrian Hunter | a293829 | 2014-10-27 15:49:23 +0200 | [diff] [blame] | 150 | int perf_session__deliver_synth_event(struct perf_session *session, |
| 151 | union perf_event *event, |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 152 | struct perf_sample *sample); |
Adrian Hunter | a293829 | 2014-10-27 15:49:23 +0200 | [diff] [blame] | 153 | |
Jiri Olsa | 89f1688 | 2018-09-13 14:54:03 +0200 | [diff] [blame] | 154 | int perf_event__process_id_index(struct perf_session *session, |
| 155 | union perf_event *event); |
Adrian Hunter | 3c659ee | 2014-10-27 15:49:22 +0200 | [diff] [blame] | 156 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 157 | #endif /* __PERF_SESSION_H */ |