blob: c8c74a1193983ab6dbc66db56dacdb157a0ba315 [file] [log] [blame]
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -03001#ifndef __PERF_MACHINE_H
2#define __PERF_MACHINE_H
3
4#include <sys/types.h>
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -03005#include <linux/rbtree.h>
6#include "map.h"
Arnaldo Carvalho de Melo58d925d2013-11-11 11:28:02 -03007#include "event.h"
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -03008
Greg Priceb21484f2012-12-06 21:48:05 -08009struct addr_location;
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030010struct branch_stack;
11struct perf_evsel;
12struct perf_sample;
13struct symbol;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030014struct thread;
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030015union perf_event;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030016
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030017/* Native host kernel uses -1 as pid index in machine */
18#define HOST_KERNEL_ID (-1)
19#define DEFAULT_GUEST_KERNEL_ID (0)
20
Adrian Hunter5512cf22014-01-29 16:14:39 +020021extern const char *ref_reloc_sym_names[];
22
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030023struct 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];
Adrian Hunter611a5ce2013-08-08 14:32:20 +030035 symbol_filter_t symbol_filter;
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030036};
37
38static inline
39struct map *machine__kernel_map(struct machine *machine, enum map_type type)
40{
41 return machine->vmlinux_maps[type];
42}
43
Jiri Olsad75e6092014-03-14 15:00:03 +010044struct thread *machine__find_thread(struct machine *machine, pid_t pid,
45 pid_t tid);
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030046
Frederic Weisbecker162f0be2013-09-11 16:18:24 +020047int machine__process_comm_event(struct machine *machine, union perf_event *event,
48 struct perf_sample *sample);
49int machine__process_exit_event(struct machine *machine, union perf_event *event,
50 struct perf_sample *sample);
51int machine__process_fork_event(struct machine *machine, union perf_event *event,
52 struct perf_sample *sample);
53int machine__process_lost_event(struct machine *machine, union perf_event *event,
54 struct perf_sample *sample);
55int machine__process_mmap_event(struct machine *machine, union perf_event *event,
56 struct perf_sample *sample);
57int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
58 struct perf_sample *sample);
59int machine__process_event(struct machine *machine, union perf_event *event,
60 struct perf_sample *sample);
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030061
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030062typedef void (*machine__process_t)(struct machine *machine, void *data);
63
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030064struct machines {
65 struct machine host;
66 struct rb_root guests;
Adrian Hunter611a5ce2013-08-08 14:32:20 +030067 symbol_filter_t symbol_filter;
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030068};
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030069
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030070void machines__init(struct machines *machines);
71void machines__exit(struct machines *machines);
72
73void machines__process_guests(struct machines *machines,
74 machine__process_t process, void *data);
75
76struct machine *machines__add(struct machines *machines, pid_t pid,
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030077 const char *root_dir);
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030078struct machine *machines__find_host(struct machines *machines);
79struct machine *machines__find(struct machines *machines, pid_t pid);
80struct machine *machines__findnew(struct machines *machines, pid_t pid);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030081
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030082void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030083char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
84
Adrian Hunter611a5ce2013-08-08 14:32:20 +030085void machines__set_symbol_filter(struct machines *machines,
86 symbol_filter_t symbol_filter);
87
David Ahern8fb598e2013-09-28 13:13:00 -060088struct machine *machine__new_host(void);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030089int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
90void machine__exit(struct machine *machine);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -030091void machine__delete_dead_threads(struct machine *machine);
92void machine__delete_threads(struct machine *machine);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030093void machine__delete(struct machine *machine);
94
Arnaldo Carvalho de Melo644f2df2014-01-22 13:15:36 -030095struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
96 struct addr_location *al);
Arnaldo Carvalho de Meloe80faac2014-01-22 13:05:06 -030097struct mem_info *sample__resolve_mem(struct perf_sample *sample,
98 struct addr_location *al);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030099int machine__resolve_callchain(struct machine *machine,
100 struct perf_evsel *evsel,
101 struct thread *thread,
102 struct perf_sample *sample,
Greg Priceb21484f2012-12-06 21:48:05 -0800103 struct symbol **parent,
Waiman Long91e95612013-10-18 10:38:48 -0400104 struct addr_location *root_al,
105 int max_stack);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300106
107/*
108 * Default guest kernel is defined by parameter --guestkallsyms
109 * and --guestmodules
110 */
111static inline bool machine__is_default_guest(struct machine *machine)
112{
113 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
114}
115
116static inline bool machine__is_host(struct machine *machine)
117{
118 return machine ? machine->pid == HOST_KERNEL_ID : false;
119}
120
Adrian Hunter314add62013-08-27 11:23:03 +0300121struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
122 pid_t tid);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300123
124size_t machine__fprintf(struct machine *machine, FILE *fp);
125
126static inline
127struct symbol *machine__find_kernel_symbol(struct machine *machine,
128 enum map_type type, u64 addr,
129 struct map **mapp,
130 symbol_filter_t filter)
131{
132 return map_groups__find_symbol(&machine->kmaps, type, addr,
133 mapp, filter);
134}
135
136static inline
137struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
138 struct map **mapp,
139 symbol_filter_t filter)
140{
141 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
142 mapp, filter);
143}
144
145static inline
146struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
147 const char *name,
148 struct map **mapp,
149 symbol_filter_t filter)
150{
151 return map_groups__find_function_by_name(&machine->kmaps, name, mapp,
152 filter);
153}
154
155struct map *machine__new_module(struct machine *machine, u64 start,
156 const char *filename);
157
158int machine__load_kallsyms(struct machine *machine, const char *filename,
159 enum map_type type, symbol_filter_t filter);
160int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
161 symbol_filter_t filter);
162
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300163size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
164 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -0300165size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
166size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300167 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300168
169void machine__destroy_kernel_maps(struct machine *machine);
170int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
171int machine__create_kernel_maps(struct machine *machine);
172
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -0300173int machines__create_kernel_maps(struct machines *machines, pid_t pid);
174int machines__create_guest_kernel_maps(struct machines *machines);
175void machines__destroy_kernel_maps(struct machines *machines);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300176
177size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
178
David Ahern35feee12013-09-28 13:12:58 -0600179int machine__for_each_thread(struct machine *machine,
180 int (*fn)(struct thread *thread, void *p),
181 void *priv);
182
Arnaldo Carvalho de Meloa33fbd52013-11-11 11:36:12 -0300183int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -0300184 struct target *target, struct thread_map *threads,
Arnaldo Carvalho de Meloa33fbd52013-11-11 11:36:12 -0300185 perf_event__handler_t process, bool data_mmap);
186static inline
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -0300187int machine__synthesize_threads(struct machine *machine, struct target *target,
Arnaldo Carvalho de Meloa33fbd52013-11-11 11:36:12 -0300188 struct thread_map *threads, bool data_mmap)
189{
190 return __machine__synthesize_threads(machine, NULL, target, threads,
191 perf_event__process, data_mmap);
192}
193
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -0300194#endif /* __PERF_MACHINE_H */