blob: 1c5823c7d6dca26da5125ce7fe948bdb9d854342 [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 Melo9de89fe2010-02-03 16:52:00 -02007#include "symbol.h"
Arnaldo Carvalho de Melo4aa65632009-12-13 19:50:29 -02008#include "thread.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -02009#include <linux/rbtree.h>
Arnaldo Carvalho de Melof823e442009-12-14 15:06:01 -020010#include "../../../include/linux/perf_event.h"
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020011
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020012struct sample_queue;
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020013struct ip_callchain;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020014struct thread;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020015
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020016struct ordered_samples {
17 u64 last_flush;
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020018 u64 next_flush;
19 u64 max_timestamp;
Thomas Gleixnera1225de2010-11-30 17:49:33 +000020 struct list_head samples;
Thomas Gleixner020bb752010-11-30 17:49:53 +000021 struct list_head sample_cache;
Thomas Gleixner5c891f32010-11-30 17:49:55 +000022 struct list_head to_free;
23 struct sample_queue *sample_buffer;
Thomas Gleixnera1225de2010-11-30 17:49:33 +000024 struct sample_queue *last_sample;
Thomas Gleixner5c891f32010-11-30 17:49:55 +000025 int sample_buffer_idx;
Arnaldo Carvalho de Melo88660562011-10-29 12:41:45 -020026 unsigned int nr_samples;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020027};
28
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020029struct perf_session {
30 struct perf_header header;
31 unsigned long size;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020032 unsigned long mmap_window;
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -030033 struct machine host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030034 struct rb_root machines;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030035 struct perf_evlist *evlist;
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030036 /*
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030037 * FIXME: Need to split this up further, we need global
38 * stats + per event stats. 'perf diff' also needs
39 * to properly support multiple events in a single
40 * perf.data file.
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030041 */
42 struct hists hists;
Arnaldo Carvalho de Meloc0198792009-12-14 14:23:00 -020043 u64 sample_type;
Frederic Weisbeckera2854122011-05-21 19:33:04 +020044 int sample_size;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020045 int fd;
Tom Zanussi8dc58102010-04-01 23:59:15 -050046 bool fd_pipe;
Tom Zanussi454c4072010-05-01 01:41:20 -050047 bool repipe;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -020048 bool sample_id_all;
49 u16 id_hdr_size;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020050 int cwdlen;
51 char *cwd;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020052 struct ordered_samples ordered_samples;
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +010053 char filename[0];
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020054};
55
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -030056struct perf_evsel;
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020057struct perf_event_ops;
58
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020059typedef int (*event_sample)(struct perf_event_ops *ops,
60 union perf_event *event, struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020061 struct perf_evsel *evsel, struct machine *machine);
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020062typedef int (*event_op)(struct perf_event_ops *ops, union perf_event *event,
63 struct perf_sample *sample,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020064 struct machine *machine);
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020065typedef int (*event_synth_op)(union perf_event *self,
66 struct perf_session *session);
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -020067typedef int (*event_attr_op)(union perf_event *event,
68 struct perf_evlist **pevlist);
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020069typedef int (*event_simple_op)(struct perf_event_ops *ops,
70 union perf_event *event);
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020071typedef int (*event_op2)(struct perf_event_ops *ops, union perf_event *event,
72 struct perf_session *session);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020073
74struct perf_event_ops {
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020075 event_sample sample,
76 read;
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -030077 event_op mmap,
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020078 comm,
79 fork,
80 exit,
81 lost,
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020082 throttle,
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -020083 unthrottle;
Arnaldo Carvalho de Melo10d0f082011-11-11 22:45:41 -020084 event_attr_op attr;
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020085 event_synth_op tracing_data;
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020086 event_simple_op event_type;
87 event_op2 finished_round,
88 build_id;
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020089 bool ordered_samples;
Ian Munsie21ef97f2010-12-10 14:09:16 +110090 bool ordering_requires_timestamps;
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020091};
92
Ian Munsie21ef97f2010-12-10 14:09:16 +110093struct perf_session *perf_session__new(const char *filename, int mode,
94 bool force, bool repipe,
95 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020096void perf_session__delete(struct perf_session *self);
97
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020098void perf_event_header__bswap(struct perf_event_header *self);
99
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -0200100int __perf_session__process_events(struct perf_session *self,
101 u64 data_offset, u64 data_size, u64 size,
102 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -0200103int perf_session__process_events(struct perf_session *self,
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -0200104 struct perf_event_ops *event_ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -0200105
Arnaldo Carvalho de Melo246d4ce2011-11-11 23:10:26 -0200106int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel *evsel,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100107 struct thread *thread,
108 struct ip_callchain *chain,
109 struct symbol **parent);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -0200110
Arnaldo Carvalho de Melod549c7692009-12-27 21:37:02 -0200111bool perf_session__has_traces(struct perf_session *self, const char *msg);
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -0200112
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200113void mem_bswap_64(void *src, int byte_size);
David Aherneda39132011-07-15 12:34:09 -0600114void perf_event__attr_swap(struct perf_event_attr *attr);
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -0200115
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800116int perf_session__create_kernel_maps(struct perf_session *self);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -0300117
Tom Zanussi8dc58102010-04-01 23:59:15 -0500118void perf_session__update_sample_type(struct perf_session *self);
Arnaldo Carvalho de Melo720a3ae2010-06-17 08:37:44 -0300119void perf_session__remove_thread(struct perf_session *self, struct thread *th);
Tom Zanussi8dc58102010-04-01 23:59:15 -0500120
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300121static inline
122struct machine *perf_session__find_host_machine(struct perf_session *self)
123{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300124 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300125}
126
127static inline
128struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
129{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300130 if (pid == HOST_KERNEL_ID)
131 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300132 return machines__find(&self->machines, pid);
133}
134
135static inline
136struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
137{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300138 if (pid == HOST_KERNEL_ID)
139 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300140 return machines__findnew(&self->machines, pid);
141}
142
143static inline
144void perf_session__process_machines(struct perf_session *self,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200145 struct perf_event_ops *ops,
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300146 machine__process_t process)
147{
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200148 process(&self->host_machine, ops);
149 return machines__process(&self->machines, process, ops);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300150}
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300151
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200152struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
153size_t perf_session__fprintf(struct perf_session *self, FILE *fp);
154
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300155size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300156
Arnaldo Carvalho de Melof8690972010-05-19 13:41:23 -0300157size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
158 FILE *fp, bool with_hits);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300159
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300160size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -0200161
162static inline int perf_session__parse_sample(struct perf_session *session,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200163 const union perf_event *event,
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200164 struct perf_sample *sample)
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -0200165{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200166 return perf_event__parse_sample(event, session->sample_type,
Frederic Weisbeckera2854122011-05-21 19:33:04 +0200167 session->sample_size,
David Ahern936be502011-09-06 09:12:26 -0600168 session->sample_id_all, sample,
169 session->header.needs_swap);
Arnaldo Carvalho de Melod0dd74e2011-01-21 13:46:41 -0200170}
171
David Ahern9cbdb702011-04-06 21:54:20 -0600172struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
173 unsigned int type);
174
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200175void perf_event__print_ip(union perf_event *event, struct perf_sample *sample,
176 struct machine *machine, struct perf_evsel *evsel,
177 int print_sym, int print_dso);
David Ahernc0230b22011-03-09 22:23:27 -0700178
Anton Blanchard5d67be92011-07-04 21:57:50 +1000179int perf_session__cpu_bitmap(struct perf_session *session,
180 const char *cpu_list, unsigned long *cpu_bitmap);
181
Stephane Eranianfbe96f22011-09-30 15:40:40 +0200182void perf_session__fprintf_info(struct perf_session *s, FILE *fp, bool full);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200183#endif /* __PERF_SESSION_H */