diff options
Diffstat (limited to 'tools/perf/util/machine.h')
| -rw-r--r-- | tools/perf/util/machine.h | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h new file mode 100644 index 000000000000..b7cde7467d55 --- /dev/null +++ b/tools/perf/util/machine.h | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | #ifndef __PERF_MACHINE_H | ||
| 2 | #define __PERF_MACHINE_H | ||
| 3 | |||
| 4 | #include <sys/types.h> | ||
| 5 | #include <linux/rbtree.h> | ||
| 6 | #include "map.h" | ||
| 7 | |||
| 8 | struct branch_stack; | ||
| 9 | struct perf_evsel; | ||
| 10 | struct perf_sample; | ||
| 11 | struct symbol; | ||
| 12 | struct thread; | ||
| 13 | union perf_event; | ||
| 14 | |||
| 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 | |||
| 39 | struct thread *machine__find_thread(struct machine *machine, pid_t pid); | ||
| 40 | |||
| 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 | |||
| 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 | |||
| 132 | size_t machine__fprintf_dsos_buildid(struct machine *machine, | ||
| 133 | FILE *fp, bool with_hits); | ||
| 134 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); | ||
| 135 | size_t machines__fprintf_dsos_buildid(struct rb_root *machines, | ||
| 136 | FILE *fp, bool with_hits); | ||
| 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 | |||
| 148 | #endif /* __PERF_MACHINE_H */ | ||
