blob: 46c854292ad6e3ab0f6306f8bb71bcf0b2451bb6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02002#ifndef __PERF_SESSION_H
3#define __PERF_SESSION_H
4
Jiri Olsa29f5ffd2013-12-03 14:09:23 +01005#include "trace-event.h"
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -02006#include "event.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02007#include "header.h"
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -03008#include "machine.h"
Jiri Olsaf5fc14122013-10-15 16:27:32 +02009#include "data.h"
Jiri Olsa5f86b802014-08-01 13:02:58 -030010#include "ordered-events.h"
Alexey Budankov5d7f4112019-03-18 20:43:35 +030011#include "util/compress.h"
Arnaldo Carvalho de Melo877a7a12017-04-17 11:39:06 -030012#include <linux/kernel.h>
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020013#include <linux/rbtree.h>
David Howellsd2709c72012-11-19 22:21:03 +000014#include <linux/perf_event.h>
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020015
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020016struct ip_callchain;
Arnaldo Carvalho de Meloe7ff8922017-04-19 21:34:35 -030017struct symbol;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020018struct thread;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020019
Adrian Hunterc4468702015-04-09 18:53:48 +030020struct auxtrace;
Adrian Hunterf6986c952015-04-09 18:53:49 +030021struct itrace_synth_opts;
Adrian Hunterc4468702015-04-09 18:53:48 +030022
Alexey Bayduraev3a3535e2021-10-13 12:06:36 +030023struct decomp_data {
24 struct decomp *decomp;
25 struct decomp *decomp_last;
26 struct zstd_data *zstd_decomp;
27};
28
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020029struct perf_session {
30 struct perf_header header;
Arnaldo Carvalho de Melo876650e62012-12-18 19:15:48 -030031 struct machines machines;
Jiri Olsa63503db2019-07-21 13:23:52 +020032 struct evlist *evlist;
Adrian Hunterc4468702015-04-09 18:53:48 +030033 struct auxtrace *auxtrace;
Adrian Hunterf6986c952015-04-09 18:53:49 +030034 struct itrace_synth_opts *itrace_synth_opts;
Adrian Hunter99fa2982015-04-30 17:37:25 +030035 struct list_head auxtrace_index;
Jiri Olsa29f5ffd2013-12-03 14:09:23 +010036 struct trace_event tevent;
Jiri Olsa72932372019-08-28 15:57:16 +020037 struct perf_record_time_conv time_conv;
Tom Zanussi454c4072010-05-01 01:41:20 -050038 bool repipe;
Adrian Hunter919d86d2014-07-14 13:02:51 +030039 bool one_mmap;
40 void *one_mmap_addr;
41 u64 one_mmap_offset;
Jiri Olsa37e39aa2014-07-06 14:23:03 +020042 struct ordered_events ordered_events;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010043 struct perf_data *data;
Arnaldo Carvalho de Melo9870d782015-03-31 12:48:16 -030044 struct perf_tool *tool;
Alexey Budankovd3c8c082019-03-18 20:41:02 +030045 u64 bytes_transferred;
46 u64 bytes_compressed;
Alexey Budankov5d7f4112019-03-18 20:43:35 +030047 struct zstd_data zstd_data;
Alexey Bayduraev3a3535e2021-10-13 12:06:36 +030048 struct decomp_data decomp_data;
49 struct decomp_data *active_decomp;
Alexey Budankovcb62c6f2019-03-18 20:45:11 +030050};
51
52struct decomp {
53 struct decomp *next;
54 u64 file_pos;
Alexey Budankov872c8ee2019-07-09 17:48:14 +030055 size_t mmap_len;
Alexey Budankovcb62c6f2019-03-18 20:45:11 +030056 u64 head;
57 size_t size;
58 char data[];
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020059};
60
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020061struct perf_tool;
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020062
Namhyung Kim2681bd82021-07-19 15:31:49 -070063struct perf_session *__perf_session__new(struct perf_data *data,
Namhyung Kim0ae03892021-07-19 15:31:50 -070064 bool repipe, int repipe_fd,
Namhyung Kim2681bd82021-07-19 15:31:49 -070065 struct perf_tool *tool);
66
67static inline struct perf_session *perf_session__new(struct perf_data *data,
68 struct perf_tool *tool)
69{
Namhyung Kim0ae03892021-07-19 15:31:50 -070070 return __perf_session__new(data, false, -1, tool);
Namhyung Kim2681bd82021-07-19 15:31:49 -070071}
72
Arnaldo Carvalho de Melo876650e62012-12-18 19:15:48 -030073void perf_session__delete(struct perf_session *session);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020074
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030075void perf_event_header__bswap(struct perf_event_header *hdr);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020076
Adrian Hunter5a52f332014-07-31 09:00:57 +030077int 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 Hunter103ed402019-11-15 14:42:20 +020081typedef int (*peek_events_cb_t)(struct perf_session *session,
82 union perf_event *event, u64 offset,
83 void *data);
84int perf_session__peek_events(struct perf_session *session, u64 offset,
85 u64 size, peek_events_cb_t cb, void *data);
Adrian Hunter5a52f332014-07-31 09:00:57 +030086
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -030087int perf_session__process_events(struct perf_session *session);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020088
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -030089int perf_session__queue_event(struct perf_session *s, union perf_event *event,
Jiri Olsadc83e132017-08-03 13:24:33 +020090 u64 timestamp, u64 file_offset);
David Ahern9c501402013-08-02 14:05:41 -060091
92void perf_tool__fill_defaults(struct perf_tool *tool);
93
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030094int perf_session__resolve_callchain(struct perf_session *session,
Jiri Olsa32dcd022019-07-21 13:23:51 +020095 struct evsel *evsel,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +010096 struct thread *thread,
97 struct ip_callchain *chain,
98 struct symbol **parent);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020099
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300100bool perf_session__has_traces(struct perf_session *session, const char *msg);
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -0200101
David Aherneda39132011-07-15 12:34:09 -0600102void perf_event__attr_swap(struct perf_event_attr *attr);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200103
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300104int perf_session__create_kernel_maps(struct perf_session *session);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300105
Arnaldo Carvalho de Melo7b56cce2012-08-01 19:31:00 -0300106void perf_session__set_id_hdr_size(struct perf_session *session);
Tom Zanussi8dc58102010-04-01 23:59:15 -0500107
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300108static inline
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300109struct machine *perf_session__find_machine(struct perf_session *session, pid_t pid)
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300110{
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300111 return machines__find(&session->machines, pid);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300112}
113
114static inline
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300115struct machine *perf_session__findnew_machine(struct perf_session *session, pid_t pid)
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300116{
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300117 return machines__findnew(&session->machines, pid);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300118}
119
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300120struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);
Masami Hiramatsu9d8b1722015-12-09 11:11:23 +0900121int perf_session__register_idle_thread(struct perf_session *session);
Namhyung Kimc53d1382015-09-30 10:45:26 +0900122
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300123size_t perf_session__fprintf(struct perf_session *session, FILE *fp);
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200124
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300125size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300126
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300127size_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 Meloc8446b92010-05-14 10:36:42 -0300129
Namhyung Kim2775de02021-04-26 18:37:15 -0700130size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp,
131 bool skip_empty);
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -0200132
Jiri Olsa32dcd022019-07-21 13:23:51 +0200133struct evsel *perf_session__find_first_evtype(struct perf_session *session,
David Ahern9cbdb702011-04-06 21:54:20 -0600134 unsigned int type);
135
Anton Blanchard5d67be92011-07-04 21:57:50 +1000136int perf_session__cpu_bitmap(struct perf_session *session,
137 const char *cpu_list, unsigned long *cpu_bitmap);
138
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200139void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300140
Jiri Olsa32dcd022019-07-21 13:23:51 +0200141struct evsel_str_handler;
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300142
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300143#define perf_session__set_tracepoints_handlers(session, array) \
Arnaldo Carvalho de Meloc0e53472019-10-01 11:14:26 -0300144 __evlist__set_tracepoints_handlers(session->evlist, array, ARRAY_SIZE(array))
Arnaldo Carvalho de Melo33e940a2013-09-17 16:34:28 -0300145
146extern volatile int session_done;
147
Mark Rutland6aa7de02017-10-23 14:07:29 -0700148#define session_done() READ_ONCE(session_done)
Adrian Hunter3c659ee2014-10-27 15:49:22 +0200149
Adrian Huntera2938292014-10-27 15:49:23 +0200150int perf_session__deliver_synth_event(struct perf_session *session,
151 union perf_event *event,
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300152 struct perf_sample *sample);
Adrian Huntera2938292014-10-27 15:49:23 +0200153
Jiri Olsa89f16882018-09-13 14:54:03 +0200154int perf_event__process_id_index(struct perf_session *session,
155 union perf_event *event);
Adrian Hunter3c659ee2014-10-27 15:49:22 +0200156
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200157#endif /* __PERF_SESSION_H */