]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/perf/util/machine.h
perf probe: Make error messages thread-safe
[mirror_ubuntu-artful-kernel.git] / tools / perf / util / machine.h
1 #ifndef __PERF_MACHINE_H
2 #define __PERF_MACHINE_H
3
4 #include <sys/types.h>
5 #include <linux/rbtree.h>
6 #include "map.h"
7 #include "event.h"
8
9 struct addr_location;
10 struct branch_stack;
11 struct perf_evsel;
12 struct perf_sample;
13 struct symbol;
14 struct thread;
15 union perf_event;
16
17 /* Native host kernel uses -1 as pid index in machine */
18 #define HOST_KERNEL_ID (-1)
19 #define DEFAULT_GUEST_KERNEL_ID (0)
20
21 extern const char *ref_reloc_sym_names[];
22
23 struct vdso_info;
24
25 struct machine {
26 struct rb_node rb_node;
27 pid_t pid;
28 u16 id_hdr_size;
29 bool comm_exec;
30 char *root_dir;
31 struct rb_root threads;
32 struct list_head dead_threads;
33 struct thread *last_match;
34 struct vdso_info *vdso_info;
35 struct list_head user_dsos;
36 struct list_head kernel_dsos;
37 struct map_groups kmaps;
38 struct map *vmlinux_maps[MAP__NR_TYPES];
39 symbol_filter_t symbol_filter;
40 pid_t *current_tid;
41 };
42
43 static inline
44 struct map *machine__kernel_map(struct machine *machine, enum map_type type)
45 {
46 return machine->vmlinux_maps[type];
47 }
48
49 struct thread *machine__find_thread(struct machine *machine, pid_t pid,
50 pid_t tid);
51 struct comm *machine__thread_exec_comm(struct machine *machine,
52 struct thread *thread);
53
54 int machine__process_comm_event(struct machine *machine, union perf_event *event,
55 struct perf_sample *sample);
56 int machine__process_exit_event(struct machine *machine, union perf_event *event,
57 struct perf_sample *sample);
58 int machine__process_fork_event(struct machine *machine, union perf_event *event,
59 struct perf_sample *sample);
60 int machine__process_lost_event(struct machine *machine, union perf_event *event,
61 struct perf_sample *sample);
62 int machine__process_mmap_event(struct machine *machine, union perf_event *event,
63 struct perf_sample *sample);
64 int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
65 struct perf_sample *sample);
66 int machine__process_event(struct machine *machine, union perf_event *event,
67 struct perf_sample *sample);
68
69 typedef void (*machine__process_t)(struct machine *machine, void *data);
70
71 struct machines {
72 struct machine host;
73 struct rb_root guests;
74 symbol_filter_t symbol_filter;
75 };
76
77 void machines__init(struct machines *machines);
78 void machines__exit(struct machines *machines);
79
80 void machines__process_guests(struct machines *machines,
81 machine__process_t process, void *data);
82
83 struct machine *machines__add(struct machines *machines, pid_t pid,
84 const char *root_dir);
85 struct machine *machines__find_host(struct machines *machines);
86 struct machine *machines__find(struct machines *machines, pid_t pid);
87 struct machine *machines__findnew(struct machines *machines, pid_t pid);
88
89 void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
90 char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
91
92 void machines__set_symbol_filter(struct machines *machines,
93 symbol_filter_t symbol_filter);
94 void machines__set_comm_exec(struct machines *machines, bool comm_exec);
95
96 struct machine *machine__new_host(void);
97 int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
98 void machine__exit(struct machine *machine);
99 void machine__delete_dead_threads(struct machine *machine);
100 void machine__delete_threads(struct machine *machine);
101 void machine__delete(struct machine *machine);
102
103 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
104 struct addr_location *al);
105 struct mem_info *sample__resolve_mem(struct perf_sample *sample,
106 struct addr_location *al);
107 int machine__resolve_callchain(struct machine *machine,
108 struct perf_evsel *evsel,
109 struct thread *thread,
110 struct perf_sample *sample,
111 struct symbol **parent,
112 struct addr_location *root_al,
113 int max_stack);
114
115 /*
116 * Default guest kernel is defined by parameter --guestkallsyms
117 * and --guestmodules
118 */
119 static inline bool machine__is_default_guest(struct machine *machine)
120 {
121 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
122 }
123
124 static inline bool machine__is_host(struct machine *machine)
125 {
126 return machine ? machine->pid == HOST_KERNEL_ID : false;
127 }
128
129 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
130 pid_t tid);
131
132 size_t machine__fprintf(struct machine *machine, FILE *fp);
133
134 static inline
135 struct symbol *machine__find_kernel_symbol(struct machine *machine,
136 enum map_type type, u64 addr,
137 struct map **mapp,
138 symbol_filter_t filter)
139 {
140 return map_groups__find_symbol(&machine->kmaps, type, addr,
141 mapp, filter);
142 }
143
144 static inline
145 struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
146 struct map **mapp,
147 symbol_filter_t filter)
148 {
149 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
150 mapp, filter);
151 }
152
153 static inline
154 struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
155 const char *name,
156 struct map **mapp,
157 symbol_filter_t filter)
158 {
159 return map_groups__find_function_by_name(&machine->kmaps, name, mapp,
160 filter);
161 }
162
163 struct map *machine__new_module(struct machine *machine, u64 start,
164 const char *filename);
165
166 int machine__load_kallsyms(struct machine *machine, const char *filename,
167 enum map_type type, symbol_filter_t filter);
168 int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
169 symbol_filter_t filter);
170
171 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
172 bool (skip)(struct dso *dso, int parm), int parm);
173 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
174 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
175 bool (skip)(struct dso *dso, int parm), int parm);
176
177 void machine__destroy_kernel_maps(struct machine *machine);
178 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
179 int machine__create_kernel_maps(struct machine *machine);
180
181 int machines__create_kernel_maps(struct machines *machines, pid_t pid);
182 int machines__create_guest_kernel_maps(struct machines *machines);
183 void machines__destroy_kernel_maps(struct machines *machines);
184
185 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
186
187 int machine__for_each_thread(struct machine *machine,
188 int (*fn)(struct thread *thread, void *p),
189 void *priv);
190
191 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
192 struct target *target, struct thread_map *threads,
193 perf_event__handler_t process, bool data_mmap);
194 static inline
195 int machine__synthesize_threads(struct machine *machine, struct target *target,
196 struct thread_map *threads, bool data_mmap)
197 {
198 return __machine__synthesize_threads(machine, NULL, target, threads,
199 perf_event__process, data_mmap);
200 }
201
202 pid_t machine__get_current_tid(struct machine *machine, int cpu);
203 int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
204 pid_t tid);
205
206 #endif /* __PERF_MACHINE_H */