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