callchain.h 1.7 KB
Newer Older
1 2 3 4
#ifndef __PERF_CALLCHAIN_H
#define __PERF_CALLCHAIN_H

#include "../perf.h"
5
#include <linux/list.h>
6
#include <linux/rbtree.h>
7
#include "event.h"
8
#include "symbol.h"
9

10
enum chain_mode {
11
	CHAIN_NONE,
12 13 14
	CHAIN_FLAT,
	CHAIN_GRAPH_ABS,
	CHAIN_GRAPH_REL
15
};
16 17 18 19

struct callchain_node {
	struct callchain_node	*parent;
	struct list_head	brothers;
20 21
	struct list_head	children;
	struct list_head	val;
22 23
	struct rb_node		rb_node; /* to sort nodes in an rbtree */
	struct rb_root		rb_root; /* sorted tree of children */
24 25
	unsigned int		val_nr;
	u64			hit;
26
	u64			children_hit;
27 28
};

29 30 31 32 33
struct callchain_root {
	u64			max_depth;
	struct callchain_node	node;
};

34 35
struct callchain_param;

36
typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
37 38 39 40
				 u64, struct callchain_param *);

struct callchain_param {
	enum chain_mode 	mode;
41
	u32			print_limit;
42 43 44 45
	double			min_percent;
	sort_chain_func_t	sort;
};

46
struct callchain_list {
47
	u64			ip;
48
	struct map_symbol	ms;
49 50 51
	struct list_head	list;
};

52
static inline void callchain_init(struct callchain_root *root)
53
{
54 55 56
	INIT_LIST_HEAD(&root->node.brothers);
	INIT_LIST_HEAD(&root->node.children);
	INIT_LIST_HEAD(&root->node.val);
57

58 59 60
	root->node.parent = NULL;
	root->node.hit = 0;
	root->max_depth = 0;
61 62
}

63 64 65 66 67
static inline u64 cumul_hits(struct callchain_node *node)
{
	return node->hit + node->children_hit;
}

68
int register_callchain_param(struct callchain_param *param);
69 70
int callchain_append(struct callchain_root *root, struct ip_callchain *chain,
		     struct map_symbol *syms, u64 period);
71
int callchain_merge(struct callchain_root *dst, struct callchain_root *src);
72

73
bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event);
74
#endif	/* __PERF_CALLCHAIN_H */