Merge branch 'linus' into x86/urgent
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / tools / perf / util / session.h
CommitLineData
94c744b6
ACM
1#ifndef __PERF_SESSION_H
2#define __PERF_SESSION_H
3
1c02c4d2 4#include "hist.h"
301a0b02 5#include "event.h"
94c744b6 6#include "header.h"
9de89fe7 7#include "symbol.h"
4aa65636 8#include "thread.h"
b3165f41 9#include <linux/rbtree.h>
f823e441 10#include "../../../include/linux/perf_event.h"
b3165f41 11
c61e52ee 12struct sample_queue;
a328626b 13struct ip_callchain;
b3165f41 14struct thread;
94c744b6 15
c61e52ee
FW
16struct ordered_samples {
17 u64 last_flush;
d6b17beb
FW
18 u64 next_flush;
19 u64 max_timestamp;
a1225dec 20 struct list_head samples;
020bb75a 21 struct list_head sample_cache;
5c891f38
TG
22 struct list_head to_free;
23 struct sample_queue *sample_buffer;
a1225dec 24 struct sample_queue *last_sample;
5c891f38 25 int sample_buffer_idx;
c61e52ee
FW
26};
27
94c744b6
ACM
28struct perf_session {
29 struct perf_header header;
30 unsigned long size;
ec913369 31 unsigned long mmap_window;
b3165f41 32 struct rb_root threads;
720a3aeb 33 struct list_head dead_threads;
b3165f41 34 struct thread *last_match;
1f626bc3 35 struct machine host_machine;
23346f21 36 struct rb_root machines;
e248de33 37 struct perf_evlist *evlist;
1c02c4d2 38 /*
e248de33
ACM
39 * FIXME: Need to split this up further, we need global
40 * stats + per event stats. 'perf diff' also needs
41 * to properly support multiple events in a single
42 * perf.data file.
1c02c4d2
ACM
43 */
44 struct hists hists;
c019879b 45 u64 sample_type;
94c744b6 46 int fd;
8dc58101 47 bool fd_pipe;
454c407e 48 bool repipe;
9c90a61c
ACM
49 bool sample_id_all;
50 u16 id_hdr_size;
ec913369
ACM
51 int cwdlen;
52 char *cwd;
c61e52ee 53 struct ordered_samples ordered_samples;
1b3a0e95
FW
54 struct callchain_cursor callchain_cursor;
55 char filename[0];
94c744b6
ACM
56};
57
d6b17beb
FW
58struct perf_event_ops;
59
8115d60c 60typedef int (*event_op)(union perf_event *self, struct perf_sample *sample,
640c03ce 61 struct perf_session *session);
8115d60c
ACM
62typedef int (*event_synth_op)(union perf_event *self,
63 struct perf_session *session);
64typedef int (*event_op2)(union perf_event *self, struct perf_session *session,
d6b17beb 65 struct perf_event_ops *ops);
301a0b02
ACM
66
67struct perf_event_ops {
d6b17beb
FW
68 event_op sample,
69 mmap,
70 comm,
71 fork,
72 exit,
73 lost,
74 read,
75 throttle,
640c03ce
ACM
76 unthrottle;
77 event_synth_op attr,
d6b17beb
FW
78 event_type,
79 tracing_data,
80 build_id;
81 event_op2 finished_round;
82 bool ordered_samples;
21ef97f0 83 bool ordering_requires_timestamps;
301a0b02
ACM
84};
85
21ef97f0
IM
86struct perf_session *perf_session__new(const char *filename, int mode,
87 bool force, bool repipe,
88 struct perf_event_ops *ops);
94c744b6
ACM
89void perf_session__delete(struct perf_session *self);
90
ba21594c
ACM
91void perf_event_header__bswap(struct perf_event_header *self);
92
6122e4e4
ACM
93int __perf_session__process_events(struct perf_session *self,
94 u64 data_offset, u64 data_size, u64 size,
95 struct perf_event_ops *ops);
301a0b02 96int perf_session__process_events(struct perf_session *self,
ec913369 97 struct perf_event_ops *event_ops);
301a0b02 98
1b3a0e95
FW
99int perf_session__resolve_callchain(struct perf_session *self,
100 struct thread *thread,
101 struct ip_callchain *chain,
102 struct symbol **parent);
a328626b 103
d549c769 104bool perf_session__has_traces(struct perf_session *self, const char *msg);
27295592 105
a1645ce1 106int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
56b03f3c
ACM
107 const char *symbol_name,
108 u64 addr);
56b03f3c 109
ba21594c
ACM
110void mem_bswap_64(void *src, int byte_size);
111
a1645ce1 112int perf_session__create_kernel_maps(struct perf_session *self);
f9224c5c 113
8dc58101 114void perf_session__update_sample_type(struct perf_session *self);
720a3aeb 115void perf_session__remove_thread(struct perf_session *self, struct thread *th);
8dc58101 116
23346f21
ACM
117static inline
118struct machine *perf_session__find_host_machine(struct perf_session *self)
119{
1f626bc3 120 return &self->host_machine;
23346f21
ACM
121}
122
123static inline
124struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
125{
1f626bc3
ACM
126 if (pid == HOST_KERNEL_ID)
127 return &self->host_machine;
23346f21
ACM
128 return machines__find(&self->machines, pid);
129}
130
131static inline
132struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
133{
1f626bc3
ACM
134 if (pid == HOST_KERNEL_ID)
135 return &self->host_machine;
23346f21
ACM
136 return machines__findnew(&self->machines, pid);
137}
138
139static inline
140void perf_session__process_machines(struct perf_session *self,
141 machine__process_t process)
142{
1f626bc3 143 process(&self->host_machine, self);
23346f21
ACM
144 return machines__process(&self->machines, process, self);
145}
cbf69680 146
1f626bc3 147size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
cbf69680 148
f869097e
ACM
149size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
150 FILE *fp, bool with_hits);
c8446b9b 151
e248de33 152size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
d0dd74e8
ACM
153
154static inline int perf_session__parse_sample(struct perf_session *session,
8115d60c 155 const union perf_event *event,
8d50e5b4 156 struct perf_sample *sample)
d0dd74e8 157{
8115d60c
ACM
158 return perf_event__parse_sample(event, session->sample_type,
159 session->sample_id_all, sample);
d0dd74e8
ACM
160}
161
94c744b6 162#endif /* __PERF_SESSION_H */