1 #ifndef __PERF_CALLCHAIN_H
2 #define __PERF_CALLCHAIN_H
5 #include <linux/list.h>
6 #include <linux/rbtree.h>
17 struct callchain_node
{
18 struct callchain_node
*parent
;
19 struct list_head siblings
;
20 struct list_head children
;
22 struct rb_node rb_node
; /* to sort nodes in an rbtree */
23 struct rb_root rb_root
; /* sorted tree of children */
29 struct callchain_root
{
31 struct callchain_node node
;
34 struct callchain_param
;
36 typedef void (*sort_chain_func_t
)(struct rb_root
*, struct callchain_root
*,
37 u64
, struct callchain_param
*);
39 struct callchain_param
{
43 sort_chain_func_t sort
;
46 struct callchain_list
{
49 struct list_head list
;
53 * A callchain cursor is a single linked list that
54 * let one feed a callchain progressively.
55 * It keeps persitent allocated entries to minimize
58 struct callchain_cursor_node
{
62 struct callchain_cursor_node
*next
;
65 struct callchain_cursor
{
67 struct callchain_cursor_node
*first
;
68 struct callchain_cursor_node
**last
;
70 struct callchain_cursor_node
*curr
;
73 static inline void callchain_init(struct callchain_root
*root
)
75 INIT_LIST_HEAD(&root
->node
.siblings
);
76 INIT_LIST_HEAD(&root
->node
.children
);
77 INIT_LIST_HEAD(&root
->node
.val
);
79 root
->node
.parent
= NULL
;
81 root
->node
.children_hit
= 0;
85 static inline u64
callchain_cumul_hits(struct callchain_node
*node
)
87 return node
->hit
+ node
->children_hit
;
90 int callchain_register_param(struct callchain_param
*param
);
91 int callchain_append(struct callchain_root
*root
,
92 struct callchain_cursor
*cursor
,
95 int callchain_merge(struct callchain_cursor
*cursor
,
96 struct callchain_root
*dst
, struct callchain_root
*src
);
98 bool ip_callchain__valid(struct ip_callchain
*chain
,
99 const union perf_event
*event
);
101 * Initialize a cursor before adding entries inside, but keep
102 * the previously allocated entries as a cache.
104 static inline void callchain_cursor_reset(struct callchain_cursor
*cursor
)
107 cursor
->last
= &cursor
->first
;
110 int callchain_cursor_append(struct callchain_cursor
*cursor
, u64 ip
,
111 struct map
*map
, struct symbol
*sym
);
113 /* Close a cursor writing session. Initialize for the reader */
114 static inline void callchain_cursor_commit(struct callchain_cursor
*cursor
)
116 cursor
->curr
= cursor
->first
;
120 /* Cursor reading iteration helpers */
121 static inline struct callchain_cursor_node
*
122 callchain_cursor_current(struct callchain_cursor
*cursor
)
124 if (cursor
->pos
== cursor
->nr
)
130 static inline void callchain_cursor_advance(struct callchain_cursor
*cursor
)
132 cursor
->curr
= cursor
->curr
->next
;
135 #endif /* __PERF_CALLCHAIN_H */