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 | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 7 | |
Greg Price | b21484f | 2012-12-06 21:48:05 -0800 | [diff] [blame^] | 8 | struct addr_location; |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 9 | struct branch_stack; |
| 10 | struct perf_evsel; |
| 11 | struct perf_sample; |
| 12 | struct symbol; |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 13 | struct thread; |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 14 | union perf_event; |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 15 | |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 16 | /* Native host kernel uses -1 as pid index in machine */ |
| 17 | #define HOST_KERNEL_ID (-1) |
| 18 | #define DEFAULT_GUEST_KERNEL_ID (0) |
| 19 | |
| 20 | struct machine { |
| 21 | struct rb_node rb_node; |
| 22 | pid_t pid; |
| 23 | u16 id_hdr_size; |
| 24 | char *root_dir; |
| 25 | struct rb_root threads; |
| 26 | struct list_head dead_threads; |
| 27 | struct thread *last_match; |
| 28 | struct list_head user_dsos; |
| 29 | struct list_head kernel_dsos; |
| 30 | struct map_groups kmaps; |
| 31 | struct map *vmlinux_maps[MAP__NR_TYPES]; |
| 32 | }; |
| 33 | |
| 34 | static inline |
| 35 | struct map *machine__kernel_map(struct machine *machine, enum map_type type) |
| 36 | { |
| 37 | return machine->vmlinux_maps[type]; |
| 38 | } |
| 39 | |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 40 | 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] | 41 | |
Arnaldo Carvalho de Melo | b0a7d1a | 2012-10-06 16:26:02 -0300 | [diff] [blame] | 42 | int machine__process_comm_event(struct machine *machine, union perf_event *event); |
| 43 | int machine__process_exit_event(struct machine *machine, union perf_event *event); |
| 44 | int machine__process_fork_event(struct machine *machine, union perf_event *event); |
| 45 | int machine__process_lost_event(struct machine *machine, union perf_event *event); |
| 46 | int machine__process_mmap_event(struct machine *machine, union perf_event *event); |
| 47 | int machine__process_event(struct machine *machine, union perf_event *event); |
| 48 | |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 49 | typedef void (*machine__process_t)(struct machine *machine, void *data); |
| 50 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 51 | struct machines { |
| 52 | struct machine host; |
| 53 | struct rb_root guests; |
| 54 | }; |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 55 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 56 | void machines__init(struct machines *machines); |
| 57 | void machines__exit(struct machines *machines); |
| 58 | |
| 59 | void machines__process_guests(struct machines *machines, |
| 60 | machine__process_t process, void *data); |
| 61 | |
| 62 | struct machine *machines__add(struct machines *machines, pid_t pid, |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 63 | const char *root_dir); |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 64 | struct machine *machines__find_host(struct machines *machines); |
| 65 | struct machine *machines__find(struct machines *machines, pid_t pid); |
| 66 | struct machine *machines__findnew(struct machines *machines, pid_t pid); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 67 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 68 | 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] | 69 | char *machine__mmap_name(struct machine *machine, char *bf, size_t size); |
| 70 | |
| 71 | int machine__init(struct machine *machine, const char *root_dir, pid_t pid); |
| 72 | void machine__exit(struct machine *machine); |
Arnaldo Carvalho de Melo | 3f067dc | 2012-12-07 17:39:39 -0300 | [diff] [blame] | 73 | void machine__delete_dead_threads(struct machine *machine); |
| 74 | void machine__delete_threads(struct machine *machine); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 75 | void machine__delete(struct machine *machine); |
| 76 | |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 77 | struct branch_info *machine__resolve_bstack(struct machine *machine, |
| 78 | struct thread *thread, |
| 79 | struct branch_stack *bs); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 80 | struct mem_info *machine__resolve_mem(struct machine *machine, |
| 81 | struct thread *thread, |
| 82 | struct perf_sample *sample, u8 cpumode); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 83 | int machine__resolve_callchain(struct machine *machine, |
| 84 | struct perf_evsel *evsel, |
| 85 | struct thread *thread, |
| 86 | struct perf_sample *sample, |
Greg Price | b21484f | 2012-12-06 21:48:05 -0800 | [diff] [blame^] | 87 | struct symbol **parent, |
| 88 | struct addr_location *root_al); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Default guest kernel is defined by parameter --guestkallsyms |
| 92 | * and --guestmodules |
| 93 | */ |
| 94 | static inline bool machine__is_default_guest(struct machine *machine) |
| 95 | { |
| 96 | return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false; |
| 97 | } |
| 98 | |
| 99 | static inline bool machine__is_host(struct machine *machine) |
| 100 | { |
| 101 | return machine ? machine->pid == HOST_KERNEL_ID : false; |
| 102 | } |
| 103 | |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 104 | struct thread *machine__findnew_thread(struct machine *machine, pid_t tid); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 105 | |
| 106 | size_t machine__fprintf(struct machine *machine, FILE *fp); |
| 107 | |
| 108 | static inline |
| 109 | struct symbol *machine__find_kernel_symbol(struct machine *machine, |
| 110 | enum map_type type, u64 addr, |
| 111 | struct map **mapp, |
| 112 | symbol_filter_t filter) |
| 113 | { |
| 114 | return map_groups__find_symbol(&machine->kmaps, type, addr, |
| 115 | mapp, filter); |
| 116 | } |
| 117 | |
| 118 | static inline |
| 119 | struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr, |
| 120 | struct map **mapp, |
| 121 | symbol_filter_t filter) |
| 122 | { |
| 123 | return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr, |
| 124 | mapp, filter); |
| 125 | } |
| 126 | |
| 127 | static inline |
| 128 | struct symbol *machine__find_kernel_function_by_name(struct machine *machine, |
| 129 | const char *name, |
| 130 | struct map **mapp, |
| 131 | symbol_filter_t filter) |
| 132 | { |
| 133 | return map_groups__find_function_by_name(&machine->kmaps, name, mapp, |
| 134 | filter); |
| 135 | } |
| 136 | |
| 137 | struct map *machine__new_module(struct machine *machine, u64 start, |
| 138 | const char *filename); |
| 139 | |
| 140 | int machine__load_kallsyms(struct machine *machine, const char *filename, |
| 141 | enum map_type type, symbol_filter_t filter); |
| 142 | int machine__load_vmlinux_path(struct machine *machine, enum map_type type, |
| 143 | symbol_filter_t filter); |
| 144 | |
Arnaldo Carvalho de Melo | 417c2ff | 2012-12-07 09:53:58 -0300 | [diff] [blame] | 145 | size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, |
| 146 | bool (skip)(struct dso *dso, int parm), int parm); |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 147 | size_t machines__fprintf_dsos(struct machines *machines, FILE *fp); |
| 148 | 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] | 149 | bool (skip)(struct dso *dso, int parm), int parm); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 150 | |
| 151 | void machine__destroy_kernel_maps(struct machine *machine); |
| 152 | int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel); |
| 153 | int machine__create_kernel_maps(struct machine *machine); |
| 154 | |
Arnaldo Carvalho de Melo | 876650e | 2012-12-18 19:15:48 -0300 | [diff] [blame] | 155 | int machines__create_kernel_maps(struct machines *machines, pid_t pid); |
| 156 | int machines__create_guest_kernel_maps(struct machines *machines); |
| 157 | void machines__destroy_kernel_maps(struct machines *machines); |
Arnaldo Carvalho de Melo | 69d2591 | 2012-11-09 11:32:52 -0300 | [diff] [blame] | 158 | |
| 159 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
| 160 | |
Arnaldo Carvalho de Melo | 9d2f8e2 | 2012-10-06 15:43:20 -0300 | [diff] [blame] | 161 | #endif /* __PERF_MACHINE_H */ |