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)
22 struct rb_node rb_node
;
26 struct rb_root threads
;
27 struct list_head dead_threads
;
28 struct thread
*last_match
;
29 struct list_head user_dsos
;
30 struct list_head kernel_dsos
;
31 struct map_groups kmaps
;
32 struct map
*vmlinux_maps
[MAP__NR_TYPES
];
33 symbol_filter_t symbol_filter
;
37 struct map
*machine__kernel_map(struct machine
*machine
, enum map_type type
)
39 return machine
->vmlinux_maps
[type
];
42 struct thread
*machine__find_thread(struct machine
*machine
, pid_t tid
);
44 int machine__process_comm_event(struct machine
*machine
, union perf_event
*event
,
45 struct perf_sample
*sample
);
46 int machine__process_exit_event(struct machine
*machine
, union perf_event
*event
,
47 struct perf_sample
*sample
);
48 int machine__process_fork_event(struct machine
*machine
, union perf_event
*event
,
49 struct perf_sample
*sample
);
50 int machine__process_lost_event(struct machine
*machine
, union perf_event
*event
,
51 struct perf_sample
*sample
);
52 int machine__process_mmap_event(struct machine
*machine
, union perf_event
*event
,
53 struct perf_sample
*sample
);
54 int machine__process_mmap2_event(struct machine
*machine
, union perf_event
*event
,
55 struct perf_sample
*sample
);
56 int machine__process_event(struct machine
*machine
, union perf_event
*event
,
57 struct perf_sample
*sample
);
59 typedef void (*machine__process_t
)(struct machine
*machine
, void *data
);
63 struct rb_root guests
;
64 symbol_filter_t symbol_filter
;
67 void machines__init(struct machines
*machines
);
68 void machines__exit(struct machines
*machines
);
70 void machines__process_guests(struct machines
*machines
,
71 machine__process_t process
, void *data
);
73 struct machine
*machines__add(struct machines
*machines
, pid_t pid
,
74 const char *root_dir
);
75 struct machine
*machines__find_host(struct machines
*machines
);
76 struct machine
*machines__find(struct machines
*machines
, pid_t pid
);
77 struct machine
*machines__findnew(struct machines
*machines
, pid_t pid
);
79 void machines__set_id_hdr_size(struct machines
*machines
, u16 id_hdr_size
);
80 char *machine__mmap_name(struct machine
*machine
, char *bf
, size_t size
);
82 void machines__set_symbol_filter(struct machines
*machines
,
83 symbol_filter_t symbol_filter
);
85 struct machine
*machine__new_host(void);
86 int machine__init(struct machine
*machine
, const char *root_dir
, pid_t pid
);
87 void machine__exit(struct machine
*machine
);
88 void machine__delete_dead_threads(struct machine
*machine
);
89 void machine__delete_threads(struct machine
*machine
);
90 void machine__delete(struct machine
*machine
);
92 struct branch_info
*machine__resolve_bstack(struct machine
*machine
,
93 struct thread
*thread
,
94 struct branch_stack
*bs
);
95 struct mem_info
*machine__resolve_mem(struct machine
*machine
,
96 struct thread
*thread
,
97 struct perf_sample
*sample
, u8 cpumode
);
98 int machine__resolve_callchain(struct machine
*machine
,
99 struct perf_evsel
*evsel
,
100 struct thread
*thread
,
101 struct perf_sample
*sample
,
102 struct symbol
**parent
,
103 struct addr_location
*root_al
,
107 * Default guest kernel is defined by parameter --guestkallsyms
110 static inline bool machine__is_default_guest(struct machine
*machine
)
112 return machine
? machine
->pid
== DEFAULT_GUEST_KERNEL_ID
: false;
115 static inline bool machine__is_host(struct machine
*machine
)
117 return machine
? machine
->pid
== HOST_KERNEL_ID
: false;
120 struct thread
*machine__findnew_thread(struct machine
*machine
, pid_t pid
,
123 size_t machine__fprintf(struct machine
*machine
, FILE *fp
);
126 struct symbol
*machine__find_kernel_symbol(struct machine
*machine
,
127 enum map_type type
, u64 addr
,
129 symbol_filter_t filter
)
131 return map_groups__find_symbol(&machine
->kmaps
, type
, addr
,
136 struct symbol
*machine__find_kernel_function(struct machine
*machine
, u64 addr
,
138 symbol_filter_t filter
)
140 return machine__find_kernel_symbol(machine
, MAP__FUNCTION
, addr
,
145 struct symbol
*machine__find_kernel_function_by_name(struct machine
*machine
,
148 symbol_filter_t filter
)
150 return map_groups__find_function_by_name(&machine
->kmaps
, name
, mapp
,
154 struct map
*machine__new_module(struct machine
*machine
, u64 start
,
155 const char *filename
);
157 int machine__load_kallsyms(struct machine
*machine
, const char *filename
,
158 enum map_type type
, symbol_filter_t filter
);
159 int machine__load_vmlinux_path(struct machine
*machine
, enum map_type type
,
160 symbol_filter_t filter
);
162 size_t machine__fprintf_dsos_buildid(struct machine
*machine
, FILE *fp
,
163 bool (skip
)(struct dso
*dso
, int parm
), int parm
);
164 size_t machines__fprintf_dsos(struct machines
*machines
, FILE *fp
);
165 size_t machines__fprintf_dsos_buildid(struct machines
*machines
, FILE *fp
,
166 bool (skip
)(struct dso
*dso
, int parm
), int parm
);
168 void machine__destroy_kernel_maps(struct machine
*machine
);
169 int __machine__create_kernel_maps(struct machine
*machine
, struct dso
*kernel
);
170 int machine__create_kernel_maps(struct machine
*machine
);
172 int machines__create_kernel_maps(struct machines
*machines
, pid_t pid
);
173 int machines__create_guest_kernel_maps(struct machines
*machines
);
174 void machines__destroy_kernel_maps(struct machines
*machines
);
176 size_t machine__fprintf_vmlinux_path(struct machine
*machine
, FILE *fp
);
178 int machine__for_each_thread(struct machine
*machine
,
179 int (*fn
)(struct thread
*thread
, void *p
),
182 int __machine__synthesize_threads(struct machine
*machine
, struct perf_tool
*tool
,
183 struct target
*target
, struct thread_map
*threads
,
184 perf_event__handler_t process
, bool data_mmap
);
186 int machine__synthesize_threads(struct machine
*machine
, struct target
*target
,
187 struct thread_map
*threads
, bool data_mmap
)
189 return __machine__synthesize_threads(machine
, NULL
, target
, threads
,
190 perf_event__process
, data_mmap
);
193 #endif /* __PERF_MACHINE_H */