blob: 14a89d2aecaf266fc685e1d87e0243f13c9a9e5a [file] [log] [blame]
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -03001#ifndef __PERF_MACHINE_H
2#define __PERF_MACHINE_H
3
4#include <sys/types.h>
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -03005#include <linux/rbtree.h>
6#include "map.h"
Arnaldo Carvalho de Melo58d925d2013-11-11 11:28:02 -03007#include "event.h"
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -03008
Greg Priceb21484f2012-12-06 21:48:05 -08009struct addr_location;
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030010struct branch_stack;
11struct perf_evsel;
12struct perf_sample;
13struct symbol;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030014struct thread;
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030015union perf_event;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030016
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030017/* Native host kernel uses -1 as pid index in machine */
18#define HOST_KERNEL_ID (-1)
19#define DEFAULT_GUEST_KERNEL_ID (0)
20
21struct 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 Hunter611a5ce2013-08-08 14:32:20 +030033 symbol_filter_t symbol_filter;
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030034};
35
36static inline
37struct map *machine__kernel_map(struct machine *machine, enum map_type type)
38{
39 return machine->vmlinux_maps[type];
40}
41
Adrian Hunter38051232013-07-04 16:20:31 +030042struct thread *machine__find_thread(struct machine *machine, pid_t tid);
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030043
Frederic Weisbecker162f0be2013-09-11 16:18:24 +020044int machine__process_comm_event(struct machine *machine, union perf_event *event,
45 struct perf_sample *sample);
46int machine__process_exit_event(struct machine *machine, union perf_event *event,
47 struct perf_sample *sample);
48int machine__process_fork_event(struct machine *machine, union perf_event *event,
49 struct perf_sample *sample);
50int machine__process_lost_event(struct machine *machine, union perf_event *event,
51 struct perf_sample *sample);
52int machine__process_mmap_event(struct machine *machine, union perf_event *event,
53 struct perf_sample *sample);
54int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
55 struct perf_sample *sample);
56int machine__process_event(struct machine *machine, union perf_event *event,
57 struct perf_sample *sample);
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030058
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030059typedef void (*machine__process_t)(struct machine *machine, void *data);
60
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030061struct machines {
62 struct machine host;
63 struct rb_root guests;
Adrian Hunter611a5ce2013-08-08 14:32:20 +030064 symbol_filter_t symbol_filter;
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030065};
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030066
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030067void machines__init(struct machines *machines);
68void machines__exit(struct machines *machines);
69
70void machines__process_guests(struct machines *machines,
71 machine__process_t process, void *data);
72
73struct machine *machines__add(struct machines *machines, pid_t pid,
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030074 const char *root_dir);
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030075struct machine *machines__find_host(struct machines *machines);
76struct machine *machines__find(struct machines *machines, pid_t pid);
77struct machine *machines__findnew(struct machines *machines, pid_t pid);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030078
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030079void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030080char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
81
Adrian Hunter611a5ce2013-08-08 14:32:20 +030082void machines__set_symbol_filter(struct machines *machines,
83 symbol_filter_t symbol_filter);
84
David Ahern8fb598e2013-09-28 13:13:00 -060085struct machine *machine__new_host(void);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030086int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
87void machine__exit(struct machine *machine);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -030088void machine__delete_dead_threads(struct machine *machine);
89void machine__delete_threads(struct machine *machine);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030090void machine__delete(struct machine *machine);
91
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030092struct branch_info *machine__resolve_bstack(struct machine *machine,
93 struct thread *thread,
94 struct branch_stack *bs);
Stephane Eranian98a3b322013-01-24 16:10:35 +010095struct mem_info *machine__resolve_mem(struct machine *machine,
96 struct thread *thread,
97 struct perf_sample *sample, u8 cpumode);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030098int machine__resolve_callchain(struct machine *machine,
99 struct perf_evsel *evsel,
100 struct thread *thread,
101 struct perf_sample *sample,
Greg Priceb21484f2012-12-06 21:48:05 -0800102 struct symbol **parent,
Waiman Long91e95612013-10-18 10:38:48 -0400103 struct addr_location *root_al,
104 int max_stack);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300105
106/*
107 * Default guest kernel is defined by parameter --guestkallsyms
108 * and --guestmodules
109 */
110static inline bool machine__is_default_guest(struct machine *machine)
111{
112 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
113}
114
115static inline bool machine__is_host(struct machine *machine)
116{
117 return machine ? machine->pid == HOST_KERNEL_ID : false;
118}
119
Adrian Hunter314add62013-08-27 11:23:03 +0300120struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
121 pid_t tid);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300122
123size_t machine__fprintf(struct machine *machine, FILE *fp);
124
125static inline
126struct 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
135static inline
136struct 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
144static inline
145struct 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
154struct map *machine__new_module(struct machine *machine, u64 start,
155 const char *filename);
156
157int machine__load_kallsyms(struct machine *machine, const char *filename,
158 enum map_type type, symbol_filter_t filter);
159int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
160 symbol_filter_t filter);
161
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300162size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
163 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -0300164size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
165size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300166 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300167
168void machine__destroy_kernel_maps(struct machine *machine);
169int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
170int machine__create_kernel_maps(struct machine *machine);
171
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -0300172int machines__create_kernel_maps(struct machines *machines, pid_t pid);
173int machines__create_guest_kernel_maps(struct machines *machines);
174void machines__destroy_kernel_maps(struct machines *machines);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300175
176size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
177
David Ahern35feee12013-09-28 13:12:58 -0600178int machine__for_each_thread(struct machine *machine,
179 int (*fn)(struct thread *thread, void *p),
180 void *priv);
181
Arnaldo Carvalho de Melo58d925d2013-11-11 11:28:02 -0300182int 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 Melo9d2f8e22012-10-06 15:43:20 -0300185#endif /* __PERF_MACHINE_H */