blob: e7fce486ebe23a299d0a3b5a5240de0795a99ebc [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;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020020 struct list_head samples_head;
21 struct sample_queue *last_inserted;
22};
23
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020024struct perf_session {
25 struct perf_header header;
26 unsigned long size;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020027 unsigned long mmap_window;
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -020028 struct rb_root threads;
29 struct thread *last_match;
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -030030 struct machine host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030031 struct rb_root machines;
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030032 struct rb_root hists_tree;
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -030033 /*
34 * FIXME: should point to the first entry in hists_tree and
35 * be a hists instance. Right now its only 'report'
36 * that is using ->hists_tree while all the rest use
37 * ->hists.
38 */
39 struct hists hists;
Arnaldo Carvalho de Meloc0198792009-12-14 14:23:00 -020040 u64 sample_type;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020041 int fd;
Tom Zanussi8dc58102010-04-01 23:59:15 -050042 bool fd_pipe;
Tom Zanussi454c4072010-05-01 01:41:20 -050043 bool repipe;
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020044 int cwdlen;
45 char *cwd;
Frederic Weisbeckerc61e52e2010-04-24 00:04:12 +020046 struct ordered_samples ordered_samples;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020047 char filename[0];
48};
49
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020050struct perf_event_ops;
51
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020052typedef int (*event_op)(event_t *self, struct perf_session *session);
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020053typedef int (*event_op2)(event_t *self, struct perf_session *session,
54 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020055
56struct perf_event_ops {
Frederic Weisbeckerd6b17be2010-05-03 15:14:33 +020057 event_op sample,
58 mmap,
59 comm,
60 fork,
61 exit,
62 lost,
63 read,
64 throttle,
65 unthrottle,
66 attr,
67 event_type,
68 tracing_data,
69 build_id;
70 event_op2 finished_round;
71 bool ordered_samples;
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020072};
73
Tom Zanussi454c4072010-05-01 01:41:20 -050074struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020075void perf_session__delete(struct perf_session *self);
76
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020077void perf_event_header__bswap(struct perf_event_header *self);
78
Arnaldo Carvalho de Melo6122e4e2010-02-03 16:52:05 -020079int __perf_session__process_events(struct perf_session *self,
80 u64 data_offset, u64 data_size, u64 size,
81 struct perf_event_ops *ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020082int perf_session__process_events(struct perf_session *self,
Arnaldo Carvalho de Meloec913362009-12-13 19:50:27 -020083 struct perf_event_ops *event_ops);
Arnaldo Carvalho de Melo301a0b02009-12-13 19:50:25 -020084
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -030085struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
86 struct thread *thread,
87 struct ip_callchain *chain,
88 struct symbol **parent);
Arnaldo Carvalho de Meloa3286262009-12-14 14:22:59 -020089
Arnaldo Carvalho de Melod549c762009-12-27 21:37:02 -020090bool perf_session__has_traces(struct perf_session *self, const char *msg);
Arnaldo Carvalho de Melo27295592009-12-27 21:37:01 -020091
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080092int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -020093 const char *symbol_name,
94 u64 addr);
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -020095
Arnaldo Carvalho de Meloba215942010-01-14 12:23:10 -020096void mem_bswap_64(void *src, int byte_size);
97
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080098int perf_session__create_kernel_maps(struct perf_session *self);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030099
Tom Zanussi8dc58102010-04-01 23:59:15 -0500100int do_read(int fd, void *buf, size_t size);
101void perf_session__update_sample_type(struct perf_session *self);
102
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300103static inline
104struct machine *perf_session__find_host_machine(struct perf_session *self)
105{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300106 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300107}
108
109static inline
110struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
111{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300112 if (pid == HOST_KERNEL_ID)
113 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300114 return machines__find(&self->machines, pid);
115}
116
117static inline
118struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
119{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300120 if (pid == HOST_KERNEL_ID)
121 return &self->host_machine;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300122 return machines__findnew(&self->machines, pid);
123}
124
125static inline
126void perf_session__process_machines(struct perf_session *self,
127 machine__process_t process)
128{
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300129 process(&self->host_machine, self);
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300130 return machines__process(&self->machines, process, self);
131}
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300132
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300133size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300134
135static inline
136size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
137 bool with_hits)
138{
139 return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
140}
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300141
142static inline
143size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp)
144{
145 return hists__fprintf_nr_events(&self->hists, fp);
146}
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200147#endif /* __PERF_SESSION_H */