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 tid
);
46 int machine__process_comm_event(struct machine
*machine
, union perf_event
*event
,
47 struct perf_sample
*sample
);
48 int machine__process_exit_event(struct machine
*machine
, union perf_event
*event
,
49 struct perf_sample
*sample
);
50 int machine__process_fork_event(struct machine
*machine
, union perf_event
*event
,
51 struct perf_sample
*sample
);
52 int machine__process_lost_event(struct machine
*machine
, union perf_event
*event
,
53 struct perf_sample
*sample
);
54 int machine__process_mmap_event(struct machine
*machine
, union perf_event
*event
,
55 struct perf_sample
*sample
);
56 int machine__process_mmap2_event(struct machine
*machine
, union perf_event
*event
,
57 struct perf_sample
*sample
);
58 int machine__process_event(struct machine
*machine
, union perf_event
*event
,
59 struct perf_sample
*sample
);
61 typedef void (*machine__process_t
)(struct machine
*machine
, void *data
);
65 struct rb_root guests
;
66 symbol_filter_t symbol_filter
;
69 void machines__init(struct machines
*machines
);
70 void machines__exit(struct machines
*machines
);
72 void machines__process_guests(struct machines
*machines
,
73 machine__process_t process
, void *data
);
75 struct machine
*machines__add(struct machines
*machines
, pid_t pid
,
76 const char *root_dir
);
77 struct machine
*machines__find_host(struct machines
*machines
);
78 struct machine
*machines__find(struct machines
*machines
, pid_t pid
);
79 struct machine
*machines__findnew(struct machines
*machines
, pid_t pid
);
81 void machines__set_id_hdr_size(struct machines
*machines
, u16 id_hdr_size
);
82 char *machine__mmap_name(struct machine
*machine
, char *bf
, size_t size
);
84 void machines__set_symbol_filter(struct machines
*machines
,
85 symbol_filter_t symbol_filter
);
87 struct machine
*machine__new_host(void);
88 int machine__init(struct machine
*machine
, const char *root_dir
, pid_t pid
);
89 void machine__exit(struct machine
*machine
);
90 void machine__delete_dead_threads(struct machine
*machine
);
91 void machine__delete_threads(struct machine
*machine
);
92 void machine__delete(struct machine
*machine
);
94 struct branch_info
*machine__resolve_bstack(struct machine
*machine
,
95 struct thread
*thread
,
96 struct branch_stack
*bs
);
97 struct mem_info
*machine__resolve_mem(struct machine
*machine
,
98 struct thread
*thread
,
99 struct perf_sample
*sample
, u8 cpumode
);
100 int machine__resolve_callchain(struct machine
*machine
,
101 struct perf_evsel
*evsel
,
102 struct thread
*thread
,
103 struct perf_sample
*sample
,
104 struct symbol
**parent
,
105 struct addr_location
*root_al
,
109 * Default guest kernel is defined by parameter --guestkallsyms
112 static inline bool machine__is_default_guest(struct machine
*machine
)
114 return machine
? machine
->pid
== DEFAULT_GUEST_KERNEL_ID
: false;
117 static inline bool machine__is_host(struct machine
*machine
)
119 return machine
? machine
->pid
== HOST_KERNEL_ID
: false;
122 struct thread
*machine__findnew_thread(struct machine
*machine
, pid_t pid
,
125 size_t machine__fprintf(struct machine
*machine
, FILE *fp
);
128 struct symbol
*machine__find_kernel_symbol(struct machine
*machine
,
129 enum map_type type
, u64 addr
,
131 symbol_filter_t filter
)
133 return map_groups__find_symbol(&machine
->kmaps
, type
, addr
,
138 struct symbol
*machine__find_kernel_function(struct machine
*machine
, u64 addr
,
140 symbol_filter_t filter
)
142 return machine__find_kernel_symbol(machine
, MAP__FUNCTION
, addr
,
147 struct symbol
*machine__find_kernel_function_by_name(struct machine
*machine
,
150 symbol_filter_t filter
)
152 return map_groups__find_function_by_name(&machine
->kmaps
, name
, mapp
,
156 struct map
*machine__new_module(struct machine
*machine
, u64 start
,
157 const char *filename
);
159 int machine__load_kallsyms(struct machine
*machine
, const char *filename
,
160 enum map_type type
, symbol_filter_t filter
);
161 int machine__load_vmlinux_path(struct machine
*machine
, enum map_type type
,
162 symbol_filter_t filter
);
164 size_t machine__fprintf_dsos_buildid(struct machine
*machine
, FILE *fp
,
165 bool (skip
)(struct dso
*dso
, int parm
), int parm
);
166 size_t machines__fprintf_dsos(struct machines
*machines
, FILE *fp
);
167 size_t machines__fprintf_dsos_buildid(struct machines
*machines
, FILE *fp
,
168 bool (skip
)(struct dso
*dso
, int parm
), int parm
);
170 void machine__destroy_kernel_maps(struct machine
*machine
);
171 int __machine__create_kernel_maps(struct machine
*machine
, struct dso
*kernel
);
172 int machine__create_kernel_maps(struct machine
*machine
);
174 int machines__create_kernel_maps(struct machines
*machines
, pid_t pid
);
175 int machines__create_guest_kernel_maps(struct machines
*machines
);
176 void machines__destroy_kernel_maps(struct machines
*machines
);
178 size_t machine__fprintf_vmlinux_path(struct machine
*machine
, FILE *fp
);
180 int machine__for_each_thread(struct machine
*machine
,
181 int (*fn
)(struct thread
*thread
, void *p
),
184 int __machine__synthesize_threads(struct machine
*machine
, struct perf_tool
*tool
,
185 struct target
*target
, struct thread_map
*threads
,
186 perf_event__handler_t process
, bool data_mmap
);
188 int machine__synthesize_threads(struct machine
*machine
, struct target
*target
,
189 struct thread_map
*threads
, bool data_mmap
)
191 return __machine__synthesize_threads(machine
, NULL
, target
, threads
,
192 perf_event__process
, data_mmap
);
195 #endif /* __PERF_MACHINE_H */