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