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