1#ifndef __PERF_CALLCHAIN_H
2#define __PERF_CALLCHAIN_H
3
4#include "../perf.h"
5#include <linux/list.h>
6#include <linux/rbtree.h>
7#include "event.h"
8#include "symbol.h"
9
10enum chain_mode {
11 CHAIN_NONE,
12 CHAIN_FLAT,
13 CHAIN_GRAPH_ABS,
14 CHAIN_GRAPH_REL
15};
16
17struct callchain_node {
18 struct callchain_node *parent;
19 struct list_head brothers;
20 struct list_head children;
21 struct list_head val;
22 struct rb_node rb_node;
23 struct rb_root rb_root;
24 unsigned int val_nr;
25 u64 hit;
26 u64 children_hit;
27};
28
29struct callchain_root {
30 u64 max_depth;
31 struct callchain_node node;
32};
33
34struct callchain_param;
35
36typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
37 u64, struct callchain_param *);
38
39struct callchain_param {
40 enum chain_mode mode;
41 u32 print_limit;
42 double min_percent;
43 sort_chain_func_t sort;
44};
45
46struct callchain_list {
47 u64 ip;
48 struct map_symbol ms;
49 struct list_head list;
50};
51
52static inline void callchain_init(struct callchain_root *root)
53{
54 INIT_LIST_HEAD(&root->node.brothers);
55 INIT_LIST_HEAD(&root->node.children);
56 INIT_LIST_HEAD(&root->node.val);
57
58 root->node.parent = NULL;
59 root->node.hit = 0;
60 root->node.children_hit = 0;
61 root->max_depth = 0;
62}
63
64static inline u64 cumul_hits(struct callchain_node *node)
65{
66 return node->hit + node->children_hit;
67}
68
69int register_callchain_param(struct callchain_param *param);
70int callchain_append(struct callchain_root *root, struct ip_callchain *chain,
71 struct map_symbol *syms, u64 period);
72int callchain_merge(struct callchain_root *dst, struct callchain_root *src);
73
74bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event);
75#endif
76