Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 1 | #ifndef __PERF_MACHINE_H |
| 2 | #define __PERF_MACHINE_H |
| 3 | |
| 4 | #include <sys/types.h> |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 5 | #include <linux/rbtree.h> |
| 6 | #include "map.h" |
Arnaldo Carvalho de Melo | 58d925d | 2013-11-11 11:28:02 -0300 | [diff] [blame^] | 7 | #include "event.h" |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 8 | |
Greg Price | b21484f | 2012-12-06 21:48:05 -0800 | [diff] [blame] | 9 | struct addr_location; |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 10 | struct branch_stack; |
| 11 | struct perf_evsel; |
| 12 | struct perf_sample; |
| 13 | struct symbol; |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 14 | struct thread; |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 15 | union perf_event; |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 16 | |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 17 | /* Native host kernel uses -1 as pid index in machine */ |
| 18 | #define HOST_KERNEL_ID (-1) |
| 19 | #define DEFAULT_GUEST_KERNEL_ID (0) |
| 20 | |
| 21 | struct machine { |
| 22 | struct rb_node rb_node; |
| 23 | pid_t pid; |
| 24 | u16 id_hdr_size; |
| 25 | char *root_dir; |
| 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]; |
Adrian Hunter | 611a5ce | 2013-08-08 14:32:20 +0300 | [diff] [blame] | 33 | symbol_filter_t symbol_filter; |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static inline |
| 37 | struct map *machine__kernel_map(struct machine *machine, enum map_type type) |
| 38 | { |
| 39 | return machine->vmlinux_maps[type]; |
| 40 | } |
| 41 | |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 42 | struct thread *machine__find_thread(struct machine *machine, pid_t tid); |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 43 | |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 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); |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 58 | |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 59 | typedef void (*machine__process_t)(struct machine *machine, void *data); |
| 60 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 61 | struct machines { |
| 62 | struct machine host; |
| 63 | struct rb_root guests; |
Adrian Hunter | 611a5ce | 2013-08-08 14:32:20 +0300 | [diff] [blame] | 64 | symbol_filter_t symbol_filter; |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 65 | }; |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 66 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 67 | void machines__init(struct machines *machines); |
| 68 | void machines__exit(struct machines *machines); |
| 69 | |
| 70 | void machines__process_guests(struct machines *machines, |
| 71 | machine__process_t process, void *data); |
| 72 | |
| 73 | struct machine *machines__add(struct machines *machines, pid_t pid, |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 74 | const char *root_dir); |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 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); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 78 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 79 | void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 80 | char *machine__mmap_name(struct machine *machine, char *bf, size_t size); |
| 81 | |
Adrian Hunter | 611a5ce | 2013-08-08 14:32:20 +0300 | [diff] [blame] | 82 | void machines__set_symbol_filter(struct machines *machines, |
| 83 | symbol_filter_t symbol_filter); |
| 84 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 85 | struct machine *machine__new_host(void); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 86 | int machine__init(struct machine *machine, const char *root_dir, pid_t pid); |
| 87 | void machine__exit(struct machine *machine); |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 88 | void machine__delete_dead_threads(struct machine *machine); |
| 89 | void machine__delete_threads(struct machine *machine); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 90 | void machine__delete(struct machine *machine); |
| 91 | |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 92 | struct branch_info *machine__resolve_bstack(struct machine *machine, |
| 93 | struct thread *thread, |
| 94 | struct branch_stack *bs); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 95 | struct mem_info *machine__resolve_mem(struct machine *machine, |
| 96 | struct thread *thread, |
| 97 | struct perf_sample *sample, u8 cpumode); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 98 | int machine__resolve_callchain(struct machine *machine, |
| 99 | struct perf_evsel *evsel, |
| 100 | struct thread *thread, |
| 101 | struct perf_sample *sample, |
Greg Price | b21484f | 2012-12-06 21:48:05 -0800 | [diff] [blame] | 102 | struct symbol **parent, |
Waiman Long | 91e9561 | 2013-10-18 10:38:48 -0400 | [diff] [blame] | 103 | struct addr_location *root_al, |
| 104 | int max_stack); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Default guest kernel is defined by parameter --guestkallsyms |
| 108 | * and --guestmodules |
| 109 | */ |
| 110 | static inline bool machine__is_default_guest(struct machine *machine) |
| 111 | { |
| 112 | return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false; |
| 113 | } |
| 114 | |
| 115 | static inline bool machine__is_host(struct machine *machine) |
| 116 | { |
| 117 | return machine ? machine->pid == HOST_KERNEL_ID : false; |
| 118 | } |
| 119 | |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 120 | struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, |
| 121 | pid_t tid); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 122 | |
| 123 | size_t machine__fprintf(struct machine *machine, FILE *fp); |
| 124 | |
| 125 | static inline |
| 126 | struct symbol *machine__find_kernel_symbol(struct machine *machine, |
| 127 | enum map_type type, u64 addr, |
| 128 | struct map **mapp, |
| 129 | symbol_filter_t filter) |
| 130 | { |
| 131 | return map_groups__find_symbol(&machine->kmaps, type, addr, |
| 132 | mapp, filter); |
| 133 | } |
| 134 | |
| 135 | static inline |
| 136 | struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr, |
| 137 | struct map **mapp, |
| 138 | symbol_filter_t filter) |
| 139 | { |
| 140 | return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr, |
| 141 | mapp, filter); |
| 142 | } |
| 143 | |
| 144 | static inline |
| 145 | struct symbol *machine__find_kernel_function_by_name(struct machine *machine, |
| 146 | const char *name, |
| 147 | struct map **mapp, |
| 148 | symbol_filter_t filter) |
| 149 | { |
| 150 | return map_groups__find_function_by_name(&machine->kmaps, name, mapp, |
| 151 | filter); |
| 152 | } |
| 153 | |
| 154 | struct map *machine__new_module(struct machine *machine, u64 start, |
| 155 | const char *filename); |
| 156 | |
| 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); |
| 161 | |
Arnaldo Carvalho de Melo | 417c2ff | 2012-12-07 09:53:58 -0300 | [diff] [blame] | 162 | size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, |
| 163 | bool (skip)(struct dso *dso, int parm), int parm); |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 164 | size_t machines__fprintf_dsos(struct machines *machines, FILE *fp); |
| 165 | size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, |
Arnaldo Carvalho de Melo | 417c2ff | 2012-12-07 09:53:58 -0300 | [diff] [blame] | 166 | bool (skip)(struct dso *dso, int parm), int parm); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 167 | |
| 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); |
| 171 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 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); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 175 | |
| 176 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
| 177 | |
David Ahern | 35feee1 | 2013-09-28 13:12:58 -0600 | [diff] [blame] | 178 | int machine__for_each_thread(struct machine *machine, |
| 179 | int (*fn)(struct thread *thread, void *p), |
| 180 | void *priv); |
| 181 | |
Arnaldo Carvalho de Melo | 58d925d | 2013-11-11 11:28:02 -0300 | [diff] [blame^] | 182 | int machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, |
| 183 | struct perf_target *target, struct thread_map *threads, |
| 184 | perf_event__handler_t process, bool data_mmap); |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 185 | #endif /* __PERF_MACHINE_H */ |