1 #ifndef __PERF_CALLCHAIN_H
2 #define __PERF_CALLCHAIN_H
5 #include <linux/list.h>
6 #include <linux/rbtree.h>
10 enum perf_call_graph_mode {
29 struct callchain_node {
30 struct callchain_node *parent;
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 */
41 struct callchain_root {
43 struct callchain_node node;
46 struct callchain_param;
48 typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
49 u64, struct callchain_param *);
56 struct callchain_param {
60 sort_chain_func_t sort;
61 enum chain_order order;
65 struct callchain_list {
68 struct list_head list;
72 * A callchain cursor is a single linked list that
73 * let one feed a callchain progressively.
74 * It keeps persistent allocated entries to minimize
77 struct callchain_cursor_node {
81 struct callchain_cursor_node *next;
84 struct callchain_cursor {
86 struct callchain_cursor_node *first;
87 struct callchain_cursor_node **last;
89 struct callchain_cursor_node *curr;
92 extern __thread struct callchain_cursor callchain_cursor;
94 static inline void callchain_init(struct callchain_root *root)
96 INIT_LIST_HEAD(&root->node.val);
98 root->node.parent = NULL;
100 root->node.children_hit = 0;
101 root->node.rb_root_in = RB_ROOT;
105 static inline u64 callchain_cumul_hits(struct callchain_node *node)
107 return node->hit + node->children_hit;
110 int callchain_register_param(struct callchain_param *param);
111 int callchain_append(struct callchain_root *root,
112 struct callchain_cursor *cursor,
115 int callchain_merge(struct callchain_cursor *cursor,
116 struct callchain_root *dst, struct callchain_root *src);
119 * Initialize a cursor before adding entries inside, but keep
120 * the previously allocated entries as a cache.
122 static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
125 cursor->last = &cursor->first;
128 int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
129 struct map *map, struct symbol *sym);
131 /* Close a cursor writing session. Initialize for the reader */
132 static inline void callchain_cursor_commit(struct callchain_cursor *cursor)
134 cursor->curr = cursor->first;
138 /* Cursor reading iteration helpers */
139 static inline struct callchain_cursor_node *
140 callchain_cursor_current(struct callchain_cursor *cursor)
142 if (cursor->pos == cursor->nr)
148 static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
150 cursor->curr = cursor->curr->next;
157 int record_parse_callchain(const char *arg, struct record_opts *opts);
158 int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
159 int record_callchain_opt(const struct option *opt, const char *arg, int unset);
161 int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
162 struct perf_evsel *evsel, struct addr_location *al,
164 int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);
165 int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node,
166 bool hide_unresolved);
168 extern const char record_callchain_help[];
169 int parse_callchain_report_opt(const char *arg);
171 static inline void callchain_cursor_snapshot(struct callchain_cursor *dest,
172 struct callchain_cursor *src)
176 dest->first = src->curr;
177 dest->nr -= src->pos;
180 #ifdef HAVE_SKIP_CALLCHAIN_IDX
181 extern int arch_skip_callchain_idx(struct machine *machine,
182 struct thread *thread, struct ip_callchain *chain);
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)
192 #endif /* __PERF_CALLCHAIN_H */