Merge branch 'perf' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2...
[pandora-kernel.git] / tools / perf / util / session.h
1 #ifndef __PERF_SESSION_H
2 #define __PERF_SESSION_H
3
4 #include "event.h"
5 #include "header.h"
6 #include "symbol.h"
7 #include "thread.h"
8 #include <linux/rbtree.h>
9 #include "../../../include/linux/perf_event.h"
10
11 struct sample_queue;
12 struct ip_callchain;
13 struct thread;
14
15 struct ordered_samples {
16         u64                     last_flush;
17         u64                     flush_limit;
18         struct list_head        samples_head;
19         struct sample_queue     *last_inserted;
20 };
21
22 struct perf_session {
23         struct perf_header      header;
24         unsigned long           size;
25         unsigned long           mmap_window;
26         struct rb_root          threads;
27         struct thread           *last_match;
28         struct rb_root          machines;
29         struct events_stats     events_stats;
30         struct rb_root          stats_by_id;
31         unsigned long           event_total[PERF_RECORD_MAX];
32         unsigned long           unknown_events;
33         struct rb_root          hists;
34         u64                     sample_type;
35         int                     fd;
36         bool                    fd_pipe;
37         int                     cwdlen;
38         char                    *cwd;
39         struct ordered_samples  ordered_samples;
40         char filename[0];
41 };
42
43 typedef int (*event_op)(event_t *self, struct perf_session *session);
44
45 struct perf_event_ops {
46         event_op sample,
47                  mmap,
48                  comm,
49                  fork,
50                  exit,
51                  lost,
52                  read,
53                  throttle,
54                  unthrottle,
55                  attr,
56                  event_type,
57                  tracing_data,
58                  build_id;
59         bool    ordered_samples;
60 };
61
62 struct perf_session *perf_session__new(const char *filename, int mode, bool force);
63 void perf_session__delete(struct perf_session *self);
64
65 void perf_event_header__bswap(struct perf_event_header *self);
66
67 int __perf_session__process_events(struct perf_session *self,
68                                    u64 data_offset, u64 data_size, u64 size,
69                                    struct perf_event_ops *ops);
70 int perf_session__process_events(struct perf_session *self,
71                                  struct perf_event_ops *event_ops);
72
73 struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
74                                                    struct thread *thread,
75                                                    struct ip_callchain *chain,
76                                                    struct symbol **parent);
77
78 bool perf_session__has_traces(struct perf_session *self, const char *msg);
79
80 int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
81                                              const char *symbol_name,
82                                              u64 addr);
83
84 void mem_bswap_64(void *src, int byte_size);
85
86 int perf_session__create_kernel_maps(struct perf_session *self);
87
88 int do_read(int fd, void *buf, size_t size);
89 void perf_session__update_sample_type(struct perf_session *self);
90
91 #ifdef NO_NEWT_SUPPORT
92 static inline int perf_session__browse_hists(struct rb_root *hists __used,
93                                               u64 nr_hists __used,
94                                               u64 session_total __used,
95                                              const char *helpline __used,
96                                              const char *input_name __used)
97 {
98         return 0;
99 }
100 #else
101 int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
102                                u64 session_total, const char *helpline,
103                                const char *input_name);
104 #endif
105
106 static inline
107 struct machine *perf_session__find_host_machine(struct perf_session *self)
108 {
109         return machines__find_host(&self->machines);
110 }
111
112 static inline
113 struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
114 {
115         return machines__find(&self->machines, pid);
116 }
117
118 static inline
119 struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
120 {
121         return machines__findnew(&self->machines, pid);
122 }
123
124 static inline
125 void perf_session__process_machines(struct perf_session *self,
126                                     machine__process_t process)
127 {
128         return machines__process(&self->machines, process, self);
129 }
130
131 static inline
132 size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
133 {
134         return machines__fprintf_dsos(&self->machines, fp);
135 }
136
137 static inline
138 size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
139                                           bool with_hits)
140 {
141         return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
142 }
143 #endif /* __PERF_SESSION_H */