blob: 0e14884f28b21e46aa8a624f4022579490d95424 [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"
Arnaldo Carvalho de Melo877a7a12017-04-17 11:39:06 -030011#include <linux/kernel.h>
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020012#include <linux/rbtree.h>
David Howellsd2709c72012-11-19 22:21:03 +000013#include <linux/perf_event.h>
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020014
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020015struct ip_callchain;
Arnaldo Carvalho de Meloe7ff8922017-04-19 21:34:35 -030016struct symbol;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020017struct thread;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020018
Adrian Hunterc4468702015-04-09 18:53:48 +030019struct auxtrace;
Adrian Hunterf6986c952015-04-09 18:53:49 +030020struct itrace_synth_opts;
Adrian Hunterc4468702015-04-09 18:53:48 +030021
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020022struct perf_session {
23 struct perf_header header;
Arnaldo Carvalho de Melo876650e62012-12-18 19:15:48 -030024 struct machines machines;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030025 struct perf_evlist *evlist;
Adrian Hunterc4468702015-04-09 18:53:48 +030026 struct auxtrace *auxtrace;
Adrian Hunterf6986c952015-04-09 18:53:49 +030027 struct itrace_synth_opts *itrace_synth_opts;
Adrian Hunter99fa2982015-04-30 17:37:25 +030028 struct list_head auxtrace_index;
Jiri Olsa29f5ffd2013-12-03 14:09:23 +010029 struct trace_event tevent;
Adrian Hunter46bc29b2016-03-08 10:38:44 +020030 struct time_conv_event time_conv;
Tom Zanussi454c4072010-05-01 01:41:20 -050031 bool repipe;
Adrian Hunter919d86d2014-07-14 13:02:51 +030032 bool one_mmap;
33 void *one_mmap_addr;
34 u64 one_mmap_offset;
Jiri Olsa37e39aa2014-07-06 14:23:03 +020035 struct ordered_events ordered_events;
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010036 struct perf_data *data;
Arnaldo Carvalho de Melo9870d782015-03-31 12:48:16 -030037 struct perf_tool *tool;
Alexey Budankovd3c8c082019-03-18 20:41:02 +030038 u64 bytes_transferred;
39 u64 bytes_compressed;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020040};
41
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020042struct perf_tool;
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020043
Jiri Olsa8ceb41d2017-01-23 22:07:59 +010044struct perf_session *perf_session__new(struct perf_data *data,
Jiri Olsaf5fc14122013-10-15 16:27:32 +020045 bool repipe, struct perf_tool *tool);
Arnaldo Carvalho de Melo876650e62012-12-18 19:15:48 -030046void perf_session__delete(struct perf_session *session);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020047
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030048void perf_event_header__bswap(struct perf_event_header *hdr);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020049
Adrian Hunter5a52f332014-07-31 09:00:57 +030050int perf_session__peek_event(struct perf_session *session, off_t file_offset,
51 void *buf, size_t buf_sz,
52 union perf_event **event_ptr,
53 struct perf_sample *sample);
54
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -030055int perf_session__process_events(struct perf_session *session);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020056
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -030057int perf_session__queue_event(struct perf_session *s, union perf_event *event,
Jiri Olsadc83e132017-08-03 13:24:33 +020058 u64 timestamp, u64 file_offset);
David Ahern9c501402013-08-02 14:05:41 -060059
60void perf_tool__fill_defaults(struct perf_tool *tool);
61
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030062int perf_session__resolve_callchain(struct perf_session *session,
63 struct perf_evsel *evsel,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +010064 struct thread *thread,
65 struct ip_callchain *chain,
66 struct symbol **parent);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020067
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030068bool perf_session__has_traces(struct perf_session *session, const char *msg);
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -020069
David Aherneda39132011-07-15 12:34:09 -060070void perf_event__attr_swap(struct perf_event_attr *attr);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020071
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030072int perf_session__create_kernel_maps(struct perf_session *session);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030073
Arnaldo Carvalho de Melo7b56cce2012-08-01 19:31:00 -030074void perf_session__set_id_hdr_size(struct perf_session *session);
Tom Zanussi8dc58102010-04-01 23:59:15 -050075
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030076static inline
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030077struct machine *perf_session__find_machine(struct perf_session *session, pid_t pid)
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030078{
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030079 return machines__find(&session->machines, pid);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030080}
81
82static inline
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030083struct machine *perf_session__findnew_machine(struct perf_session *session, pid_t pid)
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030084{
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030085 return machines__findnew(&session->machines, pid);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030086}
87
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030088struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);
Masami Hiramatsu9d8b1722015-12-09 11:11:23 +090089int perf_session__register_idle_thread(struct perf_session *session);
Namhyung Kimc53d1382015-09-30 10:45:26 +090090
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030091size_t perf_session__fprintf(struct perf_session *session, FILE *fp);
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020092
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030093size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -030094
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -030095size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp,
96 bool (fn)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -030097
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030098size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -020099
David Ahern9cbdb702011-04-06 21:54:20 -0600100struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
101 unsigned int type);
102
Anton Blanchard5d67be92011-07-04 21:57:50 +1000103int perf_session__cpu_bitmap(struct perf_session *session,
104 const char *cpu_list, unsigned long *cpu_bitmap);
105
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200106void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300107
108struct perf_evsel_str_handler;
109
110int __perf_session__set_tracepoints_handlers(struct perf_session *session,
111 const struct perf_evsel_str_handler *assocs,
112 size_t nr_assocs);
113
114#define perf_session__set_tracepoints_handlers(session, array) \
115 __perf_session__set_tracepoints_handlers(session, array, ARRAY_SIZE(array))
Arnaldo Carvalho de Melo33e940a2013-09-17 16:34:28 -0300116
117extern volatile int session_done;
118
Mark Rutland6aa7de02017-10-23 14:07:29 -0700119#define session_done() READ_ONCE(session_done)
Adrian Hunter3c659ee2014-10-27 15:49:22 +0200120
Adrian Huntera2938292014-10-27 15:49:23 +0200121int perf_session__deliver_synth_event(struct perf_session *session,
122 union perf_event *event,
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300123 struct perf_sample *sample);
Adrian Huntera2938292014-10-27 15:49:23 +0200124
Jiri Olsa89f16882018-09-13 14:54:03 +0200125int perf_event__process_id_index(struct perf_session *session,
126 union perf_event *event);
Adrian Hunter3c659ee2014-10-27 15:49:22 +0200127
128int perf_event__synthesize_id_index(struct perf_tool *tool,
129 perf_event__handler_t process,
130 struct perf_evlist *evlist,
131 struct machine *machine);
132
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200133#endif /* __PERF_SESSION_H */