blob: 646ad13005d3d9022c843d99f55eae051c0f6f7d [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
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -03008struct branch_stack;
9struct perf_evsel;
10struct perf_sample;
11struct symbol;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030012struct thread;
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030013union perf_event;
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030014
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030015/* Native host kernel uses -1 as pid index in machine */
16#define HOST_KERNEL_ID (-1)
17#define DEFAULT_GUEST_KERNEL_ID (0)
18
19struct 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
33static inline
34struct map *machine__kernel_map(struct machine *machine, enum map_type type)
35{
36 return machine->vmlinux_maps[type];
37}
38
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -030039struct thread *machine__find_thread(struct machine *machine, pid_t pid);
40
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -030041int machine__process_comm_event(struct machine *machine, union perf_event *event);
42int machine__process_exit_event(struct machine *machine, union perf_event *event);
43int machine__process_fork_event(struct machine *machine, union perf_event *event);
44int machine__process_lost_event(struct machine *machine, union perf_event *event);
45int machine__process_mmap_event(struct machine *machine, union perf_event *event);
46int machine__process_event(struct machine *machine, union perf_event *event);
47
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -030048typedef void (*machine__process_t)(struct machine *machine, void *data);
49
50void machines__process(struct rb_root *machines,
51 machine__process_t process, void *data);
52
53struct machine *machines__add(struct rb_root *machines, pid_t pid,
54 const char *root_dir);
55struct machine *machines__find_host(struct rb_root *machines);
56struct machine *machines__find(struct rb_root *machines, pid_t pid);
57struct machine *machines__findnew(struct rb_root *machines, pid_t pid);
58
59void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size);
60char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
61
62int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
63void machine__exit(struct machine *machine);
64void machine__delete(struct machine *machine);
65
66
67struct branch_info *machine__resolve_bstack(struct machine *machine,
68 struct thread *thread,
69 struct branch_stack *bs);
70int 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 */
80static inline bool machine__is_default_guest(struct machine *machine)
81{
82 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
83}
84
85static inline bool machine__is_host(struct machine *machine)
86{
87 return machine ? machine->pid == HOST_KERNEL_ID : false;
88}
89
90struct thread *machine__findnew_thread(struct machine *machine, pid_t pid);
91void machine__remove_thread(struct machine *machine, struct thread *th);
92
93size_t machine__fprintf(struct machine *machine, FILE *fp);
94
95static inline
96struct 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
105static inline
106struct 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
114static inline
115struct 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
124struct map *machine__new_module(struct machine *machine, u64 start,
125 const char *filename);
126
127int machine__load_kallsyms(struct machine *machine, const char *filename,
128 enum map_type type, symbol_filter_t filter);
129int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
130 symbol_filter_t filter);
131
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300132size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
133 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300134size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
Arnaldo Carvalho de Melo417c2ff2012-12-07 09:53:58 -0300135size_t machines__fprintf_dsos_buildid(struct rb_root *machines, FILE *fp,
136 bool (skip)(struct dso *dso, int parm), int parm);
Arnaldo Carvalho de Melo69d25912012-11-09 11:32:52 -0300137
138void machine__destroy_kernel_maps(struct machine *machine);
139int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
140int machine__create_kernel_maps(struct machine *machine);
141
142int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
143int machines__create_guest_kernel_maps(struct rb_root *machines);
144void machines__destroy_guest_kernel_maps(struct rb_root *machines);
145
146size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
147
Arnaldo Carvalho de Melo9d2f8e22012-10-06 15:43:20 -0300148#endif /* __PERF_MACHINE_H */