1 #ifndef __PERF_MACHINE_H
2 #define __PERF_MACHINE_H
5 #include <linux/rbtree.h>
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
[];
24 struct rb_node rb_node
;
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
;
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
,
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
);
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
,
108 * Default guest kernel is defined by parameter --guestkallsyms
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
,
124 size_t machine__fprintf(struct machine
*machine
, FILE *fp
);
127 struct symbol
*machine__find_kernel_symbol(struct machine
*machine
,
128 enum map_type type
, u64 addr
,
130 symbol_filter_t filter
)
132 return map_groups__find_symbol(&machine
->kmaps
, type
, addr
,
137 struct symbol
*machine__find_kernel_function(struct machine
*machine
, u64 addr
,
139 symbol_filter_t filter
)
141 return machine__find_kernel_symbol(machine
, MAP__FUNCTION
, addr
,
146 struct symbol
*machine__find_kernel_function_by_name(struct machine
*machine
,
149 symbol_filter_t filter
)
151 return map_groups__find_function_by_name(&machine
->kmaps
, name
, mapp
,
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
),
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
);
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 */