blob: 5bb6244194d5c02d44d18522807fa192f301cb3a [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 Melo9d2f8e22012-10-06 15:43:20 -03007
Greg Priceb21484f2012-12-06 21:48:05 -08008struct addr_location;
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -03009struct branch_stack;
10struct perf_evsel;
11struct perf_sample;
12struct symbol;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030013struct thread;
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030014union perf_event;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030015
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030016/* Native host kernel uses -1 as pid index in machine */
17#define HOST_KERNEL_ID (-1)
18#define DEFAULT_GUEST_KERNEL_ID (0)
19
20struct 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
34static inline
35struct map *machine__kernel_map(struct machine *machine, enum map_type type)
36{
37 return machine->vmlinux_maps[type];
38}
39
Adrian Hunter38051232013-07-04 16:20:31 +030040struct thread *machine__find_thread(struct machine *machine, pid_t tid);
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030041
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030042int machine__process_comm_event(struct machine *machine, union perf_event *event);
43int machine__process_exit_event(struct machine *machine, union perf_event *event);
44int machine__process_fork_event(struct machine *machine, union perf_event *event);
45int machine__process_lost_event(struct machine *machine, union perf_event *event);
46int machine__process_mmap_event(struct machine *machine, union perf_event *event);
47int machine__process_event(struct machine *machine, union perf_event *event);
48
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030049typedef void (*machine__process_t)(struct machine *machine, void *data);
50
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030051struct machines {
52 struct machine host;
53 struct rb_root guests;
54};
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030055
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030056void machines__init(struct machines *machines);
57void machines__exit(struct machines *machines);
58
59void machines__process_guests(struct machines *machines,
60 machine__process_t process, void *data);
61
62struct machine *machines__add(struct machines *machines, pid_t pid,
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030063 const char *root_dir);
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030064struct machine *machines__find_host(struct machines *machines);
65struct machine *machines__find(struct machines *machines, pid_t pid);
66struct machine *machines__findnew(struct machines *machines, pid_t pid);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030067
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -030068void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030069char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
70
71int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
72void machine__exit(struct machine *machine);
Arnaldo Carvalho de Melo3f067dc2012-12-07 17:39:39 -030073void machine__delete_dead_threads(struct machine *machine);
74void machine__delete_threads(struct machine *machine);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030075void machine__delete(struct machine *machine);
76
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030077struct branch_info *machine__resolve_bstack(struct machine *machine,
78 struct thread *thread,
79 struct branch_stack *bs);
Stephane Eranian98a3b322013-01-24 16:10:35 +010080struct mem_info *machine__resolve_mem(struct machine *machine,
81 struct thread *thread,
82 struct perf_sample *sample, u8 cpumode);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030083int machine__resolve_callchain(struct machine *machine,
84 struct perf_evsel *evsel,
85 struct thread *thread,
86 struct perf_sample *sample,
Greg Priceb21484f2012-12-06 21:48:05 -080087 struct symbol **parent,
88 struct addr_location *root_al);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030089
90/*
91 * Default guest kernel is defined by parameter --guestkallsyms
92 * and --guestmodules
93 */
94static inline bool machine__is_default_guest(struct machine *machine)
95{
96 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
97}
98
99static inline bool machine__is_host(struct machine *machine)
100{
101 return machine ? machine->pid == HOST_KERNEL_ID : false;
102}
103
Adrian Hunter38051232013-07-04 16:20:31 +0300104struct thread *machine__findnew_thread(struct machine *machine, pid_t tid);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300105
106size_t machine__fprintf(struct machine *machine, FILE *fp);
107
108static inline
109struct 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
118static inline
119struct 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
127static inline
128struct 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
137struct map *machine__new_module(struct machine *machine, u64 start,
138 const char *filename);
139
140int machine__load_kallsyms(struct machine *machine, const char *filename,
141 enum map_type type, symbol_filter_t filter);
142int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
143 symbol_filter_t filter);
144
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300145size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
146 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -0300147size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
148size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300149 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300150
151void machine__destroy_kernel_maps(struct machine *machine);
152int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
153int machine__create_kernel_maps(struct machine *machine);
154
Arnaldo Carvalho de Melo876650e2012-12-18 19:15:48 -0300155int machines__create_kernel_maps(struct machines *machines, pid_t pid);
156int machines__create_guest_kernel_maps(struct machines *machines);
157void machines__destroy_kernel_maps(struct machines *machines);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300158
159size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
160
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -0300161#endif /* __PERF_MACHINE_H */