blob: 18d1222b05a2f1fd0d9a1530a1f476f42113d18b [file] [log] [blame]
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02001#ifndef __PERF_SESSION_H
2#define __PERF_SESSION_H
3
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -03004#include "hist.h"
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -02005#include "event.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -02006#include "header.h"
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -03007#include "machine.h"
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -02008#include "symbol.h"
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -02009#include "thread.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020010#include <linux/rbtree.h>
Ingo Molnar7d380c82012-10-14 10:40:57 +020011#include "../../../include/uapi/linux/perf_event.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020012
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020013struct sample_queue;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020014struct ip_callchain;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020015struct thread;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020016
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020017struct ordered_samples {
18 u64 last_flush;
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020019 u64 next_flush;
20 u64 max_timestamp;
Thomas Gleixnera1225de2010-11-30 17:49:33 +000021 struct list_head samples;
Thomas Gleixner020bb752010-11-30 17:49:53 +000022 struct list_head sample_cache;
Thomas Gleixner5c891f32010-11-30 17:49:55 +000023 struct list_head to_free;
24 struct sample_queue *sample_buffer;
Thomas Gleixnera1225de2010-11-30 17:49:33 +000025 struct sample_queue *last_sample;
Thomas Gleixner5c891f32010-11-30 17:49:55 +000026 int sample_buffer_idx;
Arnaldo Carvalho de Melo88660562011-10-29 12:41:45 -020027 unsigned int nr_samples;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020028};
29
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020030struct perf_session {
31 struct perf_header header;
32 unsigned long size;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020033 unsigned long mmap_window;
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -030034 struct machine host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030035 struct rb_root machines;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030036 struct perf_evlist *evlist;
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -030037 struct pevent *pevent;
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030038 /*
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030039 * FIXME: Need to split this up further, we need global
Jiri Olsa863e4512012-09-06 17:46:55 +020040 * stats + per event stats.
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030041 */
42 struct hists hists;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020043 int fd;
Tom Zanussi8dc58102010-04-01 23:59:15 -050044 bool fd_pipe;
Tom Zanussi454c4072010-05-01 01:41:20 -050045 bool repipe;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020046 int cwdlen;
47 char *cwd;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020048 struct ordered_samples ordered_samples;
Robert Richter002c4fd2011-12-07 10:02:52 +010049 char filename[1];
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020050};
51
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020052struct perf_tool;
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020053
Ian Munsie21ef97f2010-12-10 14:09:16 +110054struct perf_session *perf_session__new(const char *filename, int mode,
55 bool force, bool repipe,
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020056 struct perf_tool *tool);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020057void perf_session__delete(struct perf_session *self);
58
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020059void perf_event_header__bswap(struct perf_event_header *self);
60
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -020061int __perf_session__process_events(struct perf_session *self,
62 u64 data_offset, u64 data_size, u64 size,
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020063 struct perf_tool *tool);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020064int perf_session__process_events(struct perf_session *self,
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020065 struct perf_tool *tool);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020066
Arnaldo Carvalho de Melo246d4ce2011-11-11 23:10:26 -020067int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel *evsel,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +010068 struct thread *thread,
69 struct ip_callchain *chain,
70 struct symbol **parent);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020071
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -020072bool perf_session__has_traces(struct perf_session *self, const char *msg);
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -020073
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020074void mem_bswap_64(void *src, int byte_size);
David Ahern80c01202012-06-08 11:47:51 -030075void mem_bswap_32(void *src, int byte_size);
David Aherneda39132011-07-15 12:34:09 -060076void perf_event__attr_swap(struct perf_event_attr *attr);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020077
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080078int perf_session__create_kernel_maps(struct perf_session *self);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030079
Arnaldo Carvalho de Melo7b56cce2012-08-01 19:31:00 -030080void perf_session__set_id_hdr_size(struct perf_session *session);
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -030081void perf_session__remove_thread(struct perf_session *self, struct thread *th);
Tom Zanussi8dc58102010-04-01 23:59:15 -050082
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030083static inline
84struct machine *perf_session__find_host_machine(struct perf_session *self)
85{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -030086 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030087}
88
89static inline
90struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
91{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -030092 if (pid == HOST_KERNEL_ID)
93 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030094 return machines__find(&self->machines, pid);
95}
96
97static inline
98struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
99{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300100 if (pid == HOST_KERNEL_ID)
101 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300102 return machines__findnew(&self->machines, pid);
103}
104
105static inline
106void perf_session__process_machines(struct perf_session *self,
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200107 struct perf_tool *tool,
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300108 machine__process_t process)
109{
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200110 process(&self->host_machine, tool);
111 return machines__process(&self->machines, process, tool);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300112}
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300113
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200114struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
115size_t perf_session__fprintf(struct perf_session *self, FILE *fp);
116
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300117size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300118
Arnaldo Carvalho de Melof8690972010-05-19 13:41:23 -0300119size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
120 FILE *fp, bool with_hits);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300121
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300122size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -0200123
David Ahern9cbdb702011-04-06 21:54:20 -0600124struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
125 unsigned int type);
126
Jiri Olsa71ad0f52012-08-07 15:20:46 +0200127void perf_evsel__print_ip(struct perf_evsel *evsel, union perf_event *event,
128 struct perf_sample *sample, struct machine *machine,
129 int print_sym, int print_dso, int print_symoffset);
David Ahernc0230b22011-03-09 22:23:27 -0700130
Anton Blanchard5d67be92011-07-04 21:57:50 +1000131int perf_session__cpu_bitmap(struct perf_session *session,
132 const char *cpu_list, unsigned long *cpu_bitmap);
133
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200134void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
Arnaldo Carvalho de Meloda378962012-06-27 13:08:42 -0300135
136struct perf_evsel_str_handler;
137
138int __perf_session__set_tracepoints_handlers(struct perf_session *session,
139 const struct perf_evsel_str_handler *assocs,
140 size_t nr_assocs);
141
142#define perf_session__set_tracepoints_handlers(session, array) \
143 __perf_session__set_tracepoints_handlers(session, array, ARRAY_SIZE(array))
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200144#endif /* __PERF_SESSION_H */