Commit | Line | Data |
---|---|---|
8cb76d99 FW |
1 | #ifndef __PERF_CALLCHAIN_H |
2 | #define __PERF_CALLCHAIN_H | |
3 | ||
4 | #include "../perf.h" | |
5da50258 | 5 | #include <linux/list.h> |
43cbcd8a | 6 | #include <linux/rbtree.h> |
139633c6 | 7 | #include "event.h" |
4424961a | 8 | #include "symbol.h" |
8cb76d99 | 9 | |
2c83bc08 JO |
10 | enum perf_call_graph_mode { |
11 | CALLCHAIN_NONE, | |
12 | CALLCHAIN_FP, | |
13 | CALLCHAIN_DWARF, | |
14 | CALLCHAIN_MAX | |
15 | }; | |
16 | ||
4eb3e478 | 17 | enum chain_mode { |
b1a88349 | 18 | CHAIN_NONE, |
805d127d FW |
19 | CHAIN_FLAT, |
20 | CHAIN_GRAPH_ABS, | |
21 | CHAIN_GRAPH_REL | |
4eb3e478 | 22 | }; |
8cb76d99 | 23 | |
d797fdc5 SL |
24 | enum chain_order { |
25 | ORDER_CALLER, | |
26 | ORDER_CALLEE | |
27 | }; | |
28 | ||
8cb76d99 FW |
29 | struct callchain_node { |
30 | struct callchain_node *parent; | |
f37a291c | 31 | struct list_head val; |
e369517c NK |
32 | struct rb_node rb_node_in; /* to insert nodes in an rbtree */ |
33 | struct rb_node rb_node; /* to sort nodes in an output tree */ | |
34 | struct rb_root rb_root_in; /* input tree of children */ | |
35 | struct rb_root rb_root; /* sorted output tree of children */ | |
f37a291c IM |
36 | unsigned int val_nr; |
37 | u64 hit; | |
1953287b | 38 | u64 children_hit; |
8cb76d99 FW |
39 | }; |
40 | ||
d2009c51 FW |
41 | struct callchain_root { |
42 | u64 max_depth; | |
43 | struct callchain_node node; | |
44 | }; | |
45 | ||
805d127d FW |
46 | struct callchain_param; |
47 | ||
d2009c51 | 48 | typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *, |
805d127d FW |
49 | u64, struct callchain_param *); |
50 | ||
99571ab3 AK |
51 | enum chain_key { |
52 | CCKEY_FUNCTION, | |
53 | CCKEY_ADDRESS | |
54 | }; | |
55 | ||
805d127d FW |
56 | struct callchain_param { |
57 | enum chain_mode mode; | |
232a5c94 | 58 | u32 print_limit; |
805d127d FW |
59 | double min_percent; |
60 | sort_chain_func_t sort; | |
d797fdc5 | 61 | enum chain_order order; |
99571ab3 | 62 | enum chain_key key; |
805d127d FW |
63 | }; |
64 | ||
8cb76d99 | 65 | struct callchain_list { |
f37a291c | 66 | u64 ip; |
b3c9ac08 | 67 | struct map_symbol ms; |
8cb76d99 FW |
68 | struct list_head list; |
69 | }; | |
70 | ||
1b3a0e95 FW |
71 | /* |
72 | * A callchain cursor is a single linked list that | |
73 | * let one feed a callchain progressively. | |
3fd44cd4 | 74 | * It keeps persistent allocated entries to minimize |
1b3a0e95 FW |
75 | * allocations. |
76 | */ | |
77 | struct callchain_cursor_node { | |
78 | u64 ip; | |
79 | struct map *map; | |
80 | struct symbol *sym; | |
81 | struct callchain_cursor_node *next; | |
82 | }; | |
83 | ||
84 | struct callchain_cursor { | |
85 | u64 nr; | |
86 | struct callchain_cursor_node *first; | |
87 | struct callchain_cursor_node **last; | |
88 | u64 pos; | |
89 | struct callchain_cursor_node *curr; | |
90 | }; | |
91 | ||
47260645 NK |
92 | extern __thread struct callchain_cursor callchain_cursor; |
93 | ||
d2009c51 | 94 | static inline void callchain_init(struct callchain_root *root) |
8cb76d99 | 95 | { |
d2009c51 | 96 | INIT_LIST_HEAD(&root->node.val); |
97aa1052 | 97 | |
d2009c51 FW |
98 | root->node.parent = NULL; |
99 | root->node.hit = 0; | |
98ee74a7 | 100 | root->node.children_hit = 0; |
e369517c | 101 | root->node.rb_root_in = RB_ROOT; |
d2009c51 | 102 | root->max_depth = 0; |
8cb76d99 FW |
103 | } |
104 | ||
f08c3154 | 105 | static inline u64 callchain_cumul_hits(struct callchain_node *node) |
1953287b FW |
106 | { |
107 | return node->hit + node->children_hit; | |
108 | } | |
109 | ||
16537f13 | 110 | int callchain_register_param(struct callchain_param *param); |
1b3a0e95 FW |
111 | int callchain_append(struct callchain_root *root, |
112 | struct callchain_cursor *cursor, | |
113 | u64 period); | |
114 | ||
115 | int callchain_merge(struct callchain_cursor *cursor, | |
116 | struct callchain_root *dst, struct callchain_root *src); | |
139633c6 | 117 | |
1b3a0e95 FW |
118 | /* |
119 | * Initialize a cursor before adding entries inside, but keep | |
120 | * the previously allocated entries as a cache. | |
121 | */ | |
122 | static inline void callchain_cursor_reset(struct callchain_cursor *cursor) | |
123 | { | |
124 | cursor->nr = 0; | |
125 | cursor->last = &cursor->first; | |
126 | } | |
127 | ||
128 | int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, | |
129 | struct map *map, struct symbol *sym); | |
130 | ||
131 | /* Close a cursor writing session. Initialize for the reader */ | |
132 | static inline void callchain_cursor_commit(struct callchain_cursor *cursor) | |
133 | { | |
134 | cursor->curr = cursor->first; | |
135 | cursor->pos = 0; | |
136 | } | |
137 | ||
138 | /* Cursor reading iteration helpers */ | |
139 | static inline struct callchain_cursor_node * | |
140 | callchain_cursor_current(struct callchain_cursor *cursor) | |
141 | { | |
142 | if (cursor->pos == cursor->nr) | |
143 | return NULL; | |
144 | ||
145 | return cursor->curr; | |
146 | } | |
147 | ||
148 | static inline void callchain_cursor_advance(struct callchain_cursor *cursor) | |
149 | { | |
150 | cursor->curr = cursor->curr->next; | |
151 | cursor->pos++; | |
152 | } | |
75d9a108 ACM |
153 | |
154 | struct option; | |
2dc9fb1a | 155 | struct hist_entry; |
75d9a108 | 156 | |
b4006796 | 157 | int record_parse_callchain(const char *arg, struct record_opts *opts); |
75d9a108 | 158 | int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset); |
09b0fd45 JO |
159 | int record_callchain_opt(const struct option *opt, const char *arg, int unset); |
160 | ||
2dc9fb1a NK |
161 | int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent, |
162 | struct perf_evsel *evsel, struct addr_location *al, | |
163 | int max_stack); | |
164 | int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample); | |
c7405d85 NK |
165 | int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node, |
166 | bool hide_unresolved); | |
2dc9fb1a | 167 | |
75d9a108 | 168 | extern const char record_callchain_help[]; |
cff6bb46 | 169 | int parse_callchain_report_opt(const char *arg); |
be1f13e3 NK |
170 | |
171 | static inline void callchain_cursor_snapshot(struct callchain_cursor *dest, | |
172 | struct callchain_cursor *src) | |
173 | { | |
174 | *dest = *src; | |
175 | ||
176 | dest->first = src->curr; | |
177 | dest->nr -= src->pos; | |
178 | } | |
a60335ba SB |
179 | |
180 | #ifdef HAVE_SKIP_CALLCHAIN_IDX | |
181 | extern int arch_skip_callchain_idx(struct machine *machine, | |
182 | struct thread *thread, struct ip_callchain *chain); | |
183 | #else | |
184 | static inline int arch_skip_callchain_idx(struct machine *machine __maybe_unused, | |
185 | struct thread *thread __maybe_unused, | |
186 | struct ip_callchain *chain __maybe_unused) | |
187 | { | |
188 | return -1; | |
189 | } | |
190 | #endif | |
191 | ||
8b40f521 | 192 | #endif /* __PERF_CALLCHAIN_H */ |