callchain.h 3.8 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 20 21
enum chain_order {
	ORDER_CALLER,
	ORDER_CALLEE
};

22 23
struct callchain_node {
	struct callchain_node	*parent;
24
	struct list_head	val;
25 26 27 28
	struct rb_node		rb_node_in; /* to insert nodes in an rbtree */
	struct rb_node		rb_node;    /* to sort nodes in an output tree */
	struct rb_root		rb_root_in; /* input tree of children */
	struct rb_root		rb_root;    /* sorted output tree of children */
29 30
	unsigned int		val_nr;
	u64			hit;
31
	u64			children_hit;
32 33
};

34 35 36 37 38
struct callchain_root {
	u64			max_depth;
	struct callchain_node	node;
};

39 40
struct callchain_param;

41
typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
42 43
				 u64, struct callchain_param *);

44 45 46 47 48
enum chain_key {
	CCKEY_FUNCTION,
	CCKEY_ADDRESS
};

49 50
struct callchain_param {
	enum chain_mode 	mode;
51
	u32			print_limit;
52 53
	double			min_percent;
	sort_chain_func_t	sort;
54
	enum chain_order	order;
55
	enum chain_key		key;
56 57
};

58
struct callchain_list {
59
	u64			ip;
60
	struct map_symbol	ms;
61 62 63
	struct list_head	list;
};

64 65 66
/*
 * A callchain cursor is a single linked list that
 * let one feed a callchain progressively.
67
 * It keeps persistent allocated entries to minimize
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
 * allocations.
 */
struct callchain_cursor_node {
	u64				ip;
	struct map			*map;
	struct symbol			*sym;
	struct callchain_cursor_node	*next;
};

struct callchain_cursor {
	u64				nr;
	struct callchain_cursor_node	*first;
	struct callchain_cursor_node	**last;
	u64				pos;
	struct callchain_cursor_node	*curr;
};

85 86
extern __thread struct callchain_cursor callchain_cursor;

87
static inline void callchain_init(struct callchain_root *root)
88
{
89
	INIT_LIST_HEAD(&root->node.val);
90

91 92
	root->node.parent = NULL;
	root->node.hit = 0;
93
	root->node.children_hit = 0;
94
	root->node.rb_root_in = RB_ROOT;
95
	root->max_depth = 0;
96 97
}

98
static inline u64 callchain_cumul_hits(struct callchain_node *node)
99 100 101 102
{
	return node->hit + node->children_hit;
}

103
int callchain_register_param(struct callchain_param *param);
104 105 106 107 108 109
int callchain_append(struct callchain_root *root,
		     struct callchain_cursor *cursor,
		     u64 period);

int callchain_merge(struct callchain_cursor *cursor,
		    struct callchain_root *dst, struct callchain_root *src);
110

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
/*
 * Initialize a cursor before adding entries inside, but keep
 * the previously allocated entries as a cache.
 */
static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
{
	cursor->nr = 0;
	cursor->last = &cursor->first;
}

int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
			    struct map *map, struct symbol *sym);

/* Close a cursor writing session. Initialize for the reader */
static inline void callchain_cursor_commit(struct callchain_cursor *cursor)
{
	cursor->curr = cursor->first;
	cursor->pos = 0;
}

/* Cursor reading iteration helpers */
static inline struct callchain_cursor_node *
callchain_cursor_current(struct callchain_cursor *cursor)
{
	if (cursor->pos == cursor->nr)
		return NULL;

	return cursor->curr;
}

static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
{
	cursor->curr = cursor->curr->next;
	cursor->pos++;
}
146 147

struct option;
148
struct hist_entry;
149

150
int record_parse_callchain(const char *arg, struct record_opts *opts);
151
int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
J
Jiri Olsa 已提交
152 153
int record_callchain_opt(const struct option *opt, const char *arg, int unset);

154 155 156 157 158
int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
			      struct perf_evsel *evsel, struct addr_location *al,
			      int max_stack);
int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);

159
extern const char record_callchain_help[];
160
int parse_callchain_report_opt(const char *arg);
161
#endif	/* __PERF_CALLCHAIN_H */