callchain.h 4.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 11 12 13 14 15 16
enum perf_call_graph_mode {
	CALLCHAIN_NONE,
	CALLCHAIN_FP,
	CALLCHAIN_DWARF,
	CALLCHAIN_MAX
};

17
enum chain_mode {
18
	CHAIN_NONE,
19 20 21
	CHAIN_FLAT,
	CHAIN_GRAPH_ABS,
	CHAIN_GRAPH_REL
22
};
23

24 25 26 27 28
enum chain_order {
	ORDER_CALLER,
	ORDER_CALLEE
};

29 30
struct callchain_node {
	struct callchain_node	*parent;
31
	struct list_head	val;
32 33 34 35
	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 */
36 37
	unsigned int		val_nr;
	u64			hit;
38
	u64			children_hit;
39 40
};

41 42 43 44 45
struct callchain_root {
	u64			max_depth;
	struct callchain_node	node;
};

46 47
struct callchain_param;

48
typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
49 50
				 u64, struct callchain_param *);

51 52 53 54 55
enum chain_key {
	CCKEY_FUNCTION,
	CCKEY_ADDRESS
};

56
struct callchain_param {
57 58 59
	bool			enabled;
	enum perf_call_graph_mode record_mode;
	u32			dump_size;
60
	enum chain_mode 	mode;
61
	u32			print_limit;
62 63
	double			min_percent;
	sort_chain_func_t	sort;
64
	enum chain_order	order;
65
	enum chain_key		key;
66 67
};

68
struct callchain_list {
69
	u64			ip;
70
	struct map_symbol	ms;
71 72 73
	struct list_head	list;
};

74 75 76
/*
 * A callchain cursor is a single linked list that
 * let one feed a callchain progressively.
77
 * It keeps persistent allocated entries to minimize
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
 * 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;
};

95 96
extern __thread struct callchain_cursor callchain_cursor;

97
static inline void callchain_init(struct callchain_root *root)
98
{
99
	INIT_LIST_HEAD(&root->node.val);
100

101 102
	root->node.parent = NULL;
	root->node.hit = 0;
103
	root->node.children_hit = 0;
104
	root->node.rb_root_in = RB_ROOT;
105
	root->max_depth = 0;
106 107
}

108
static inline u64 callchain_cumul_hits(struct callchain_node *node)
109 110 111 112
{
	return node->hit + node->children_hit;
}

113
int callchain_register_param(struct callchain_param *param);
114 115 116 117 118 119
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);
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 146 147 148 149 150 151 152 153 154 155
/*
 * 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++;
}
156 157

struct option;
158
struct hist_entry;
159 160

int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
J
Jiri Olsa 已提交
161 162
int record_callchain_opt(const struct option *opt, const char *arg, int unset);

163 164 165 166
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);
167 168
int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node,
			bool hide_unresolved);
169

170
extern const char record_callchain_help[];
171
int parse_callchain_record_opt(const char *arg);
172
int parse_callchain_report_opt(const char *arg);
173
int perf_callchain_config(const char *var, const char *value);
174 175 176 177 178 179 180 181 182

static inline void callchain_cursor_snapshot(struct callchain_cursor *dest,
					     struct callchain_cursor *src)
{
	*dest = *src;

	dest->first = src->curr;
	dest->nr -= src->pos;
}
183 184 185 186 187 188 189 190 191 192 193 194 195

#ifdef HAVE_SKIP_CALLCHAIN_IDX
extern int arch_skip_callchain_idx(struct machine *machine,
			struct thread *thread, struct ip_callchain *chain);
#else
static inline int arch_skip_callchain_idx(struct machine *machine __maybe_unused,
			struct thread *thread __maybe_unused,
			struct ip_callchain *chain __maybe_unused)
{
	return -1;
}
#endif

196
#endif	/* __PERF_CALLCHAIN_H */