Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / tools / perf / util / machine.h
blobc8c74a1193983ab6dbc66db56dacdb157a0ba315
1 #ifndef __PERF_MACHINE_H
2 #define __PERF_MACHINE_H
4 #include <sys/types.h>
5 #include <linux/rbtree.h>
6 #include "map.h"
7 #include "event.h"
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;
17 /* Native host kernel uses -1 as pid index in machine */
18 #define HOST_KERNEL_ID (-1)
19 #define DEFAULT_GUEST_KERNEL_ID (0)
21 extern const char *ref_reloc_sym_names[];
23 struct machine {
24 struct rb_node rb_node;
25 pid_t pid;
26 u16 id_hdr_size;
27 char *root_dir;
28 struct rb_root threads;
29 struct list_head dead_threads;
30 struct thread *last_match;
31 struct list_head user_dsos;
32 struct list_head kernel_dsos;
33 struct map_groups kmaps;
34 struct map *vmlinux_maps[MAP__NR_TYPES];
35 symbol_filter_t symbol_filter;
38 static inline
39 struct map *machine__kernel_map(struct machine *machine, enum map_type type)
41 return machine->vmlinux_maps[type];
44 struct thread *machine__find_thread(struct machine *machine, pid_t pid,
45 pid_t tid);
47 int machine__process_comm_event(struct machine *machine, union perf_event *event,
48 struct perf_sample *sample);
49 int machine__process_exit_event(struct machine *machine, union perf_event *event,
50 struct perf_sample *sample);
51 int machine__process_fork_event(struct machine *machine, union perf_event *event,
52 struct perf_sample *sample);
53 int machine__process_lost_event(struct machine *machine, union perf_event *event,
54 struct perf_sample *sample);
55 int machine__process_mmap_event(struct machine *machine, union perf_event *event,
56 struct perf_sample *sample);
57 int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
58 struct perf_sample *sample);
59 int machine__process_event(struct machine *machine, union perf_event *event,
60 struct perf_sample *sample);
62 typedef void (*machine__process_t)(struct machine *machine, void *data);
64 struct machines {
65 struct machine host;
66 struct rb_root guests;
67 symbol_filter_t symbol_filter;
70 void machines__init(struct machines *machines);
71 void machines__exit(struct machines *machines);
73 void machines__process_guests(struct machines *machines,
74 machine__process_t process, void *data);
76 struct machine *machines__add(struct machines *machines, pid_t pid,
77 const char *root_dir);
78 struct machine *machines__find_host(struct machines *machines);
79 struct machine *machines__find(struct machines *machines, pid_t pid);
80 struct machine *machines__findnew(struct machines *machines, pid_t pid);
82 void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
83 char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
85 void machines__set_symbol_filter(struct machines *machines,
86 symbol_filter_t symbol_filter);
88 struct machine *machine__new_host(void);
89 int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
90 void machine__exit(struct machine *machine);
91 void machine__delete_dead_threads(struct machine *machine);
92 void machine__delete_threads(struct machine *machine);
93 void machine__delete(struct machine *machine);
95 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
96 struct addr_location *al);
97 struct mem_info *sample__resolve_mem(struct perf_sample *sample,
98 struct addr_location *al);
99 int machine__resolve_callchain(struct machine *machine,
100 struct perf_evsel *evsel,
101 struct thread *thread,
102 struct perf_sample *sample,
103 struct symbol **parent,
104 struct addr_location *root_al,
105 int max_stack);
108 * Default guest kernel is defined by parameter --guestkallsyms
109 * and --guestmodules
111 static inline bool machine__is_default_guest(struct machine *machine)
113 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
116 static inline bool machine__is_host(struct machine *machine)
118 return machine ? machine->pid == HOST_KERNEL_ID : false;
121 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
122 pid_t tid);
124 size_t machine__fprintf(struct machine *machine, FILE *fp);
126 static inline
127 struct symbol *machine__find_kernel_symbol(struct machine *machine,
128 enum map_type type, u64 addr,
129 struct map **mapp,
130 symbol_filter_t filter)
132 return map_groups__find_symbol(&machine->kmaps, type, addr,
133 mapp, filter);
136 static inline
137 struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
138 struct map **mapp,
139 symbol_filter_t filter)
141 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
142 mapp, filter);
145 static inline
146 struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
147 const char *name,
148 struct map **mapp,
149 symbol_filter_t filter)
151 return map_groups__find_function_by_name(&machine->kmaps, name, mapp,
152 filter);
155 struct map *machine__new_module(struct machine *machine, u64 start,
156 const char *filename);
158 int machine__load_kallsyms(struct machine *machine, const char *filename,
159 enum map_type type, symbol_filter_t filter);
160 int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
161 symbol_filter_t filter);
163 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
164 bool (skip)(struct dso *dso, int parm), int parm);
165 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
166 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
167 bool (skip)(struct dso *dso, int parm), int parm);
169 void machine__destroy_kernel_maps(struct machine *machine);
170 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
171 int machine__create_kernel_maps(struct machine *machine);
173 int machines__create_kernel_maps(struct machines *machines, pid_t pid);
174 int machines__create_guest_kernel_maps(struct machines *machines);
175 void machines__destroy_kernel_maps(struct machines *machines);
177 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
179 int machine__for_each_thread(struct machine *machine,
180 int (*fn)(struct thread *thread, void *p),
181 void *priv);
183 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
184 struct target *target, struct thread_map *threads,
185 perf_event__handler_t process, bool data_mmap);
186 static inline
187 int machine__synthesize_threads(struct machine *machine, struct target *target,
188 struct thread_map *threads, bool data_mmap)
190 return __machine__synthesize_threads(machine, NULL, target, threads,
191 perf_event__process, data_mmap);
194 #endif /* __PERF_MACHINE_H */