| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 1 | #ifndef __PERF_CALLCHAIN_H | 
|  | 2 | #define __PERF_CALLCHAIN_H | 
|  | 3 |  | 
|  | 4 | #include "../perf.h" | 
| Arnaldo Carvalho de Melo | 5da5025 | 2009-07-01 14:46:08 -0300 | [diff] [blame] | 5 | #include <linux/list.h> | 
| Arnaldo Carvalho de Melo | 43cbcd8 | 2009-07-01 12:28:37 -0300 | [diff] [blame] | 6 | #include <linux/rbtree.h> | 
| Arnaldo Carvalho de Melo | 139633c | 2010-05-09 11:47:13 -0300 | [diff] [blame] | 7 | #include "event.h" | 
| Frederic Weisbecker | 4424961 | 2009-07-01 05:35:14 +0200 | [diff] [blame] | 8 | #include "symbol.h" | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 9 |  | 
| Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 10 | enum chain_mode { | 
| Frederic Weisbecker | b1a8834 | 2009-08-08 02:16:24 +0200 | [diff] [blame] | 11 | CHAIN_NONE, | 
| Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 12 | CHAIN_FLAT, | 
|  | 13 | CHAIN_GRAPH_ABS, | 
|  | 14 | CHAIN_GRAPH_REL | 
| Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 15 | }; | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 16 |  | 
| Sam Liao | d797fdc | 2011-06-07 23:49:46 +0800 | [diff] [blame] | 17 | enum chain_order { | 
|  | 18 | ORDER_CALLER, | 
|  | 19 | ORDER_CALLEE | 
|  | 20 | }; | 
|  | 21 |  | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 22 | struct callchain_node { | 
|  | 23 | struct callchain_node	*parent; | 
| Frederic Weisbecker | 529363b | 2011-01-14 04:52:01 +0100 | [diff] [blame] | 24 | struct list_head	siblings; | 
| Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 25 | struct list_head	children; | 
|  | 26 | struct list_head	val; | 
| Frederic Weisbecker | 4eb3e47 | 2009-07-02 17:58:21 +0200 | [diff] [blame] | 27 | struct rb_node		rb_node; /* to sort nodes in an rbtree */ | 
|  | 28 | struct rb_root		rb_root; /* sorted tree of children */ | 
| Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 29 | unsigned int		val_nr; | 
|  | 30 | u64			hit; | 
| Frederic Weisbecker | 1953287b | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 31 | u64			children_hit; | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 32 | }; | 
|  | 33 |  | 
| Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 34 | struct callchain_root { | 
|  | 35 | u64			max_depth; | 
|  | 36 | struct callchain_node	node; | 
|  | 37 | }; | 
|  | 38 |  | 
| Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 39 | struct callchain_param; | 
|  | 40 |  | 
| Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 41 | typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *, | 
| Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 42 | u64, struct callchain_param *); | 
|  | 43 |  | 
|  | 44 | struct callchain_param { | 
|  | 45 | enum chain_mode 	mode; | 
| Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 46 | u32			print_limit; | 
| Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 47 | double			min_percent; | 
|  | 48 | sort_chain_func_t	sort; | 
| Sam Liao | d797fdc | 2011-06-07 23:49:46 +0800 | [diff] [blame] | 49 | enum chain_order	order; | 
| Frederic Weisbecker | 805d127 | 2009-07-05 07:39:21 +0200 | [diff] [blame] | 50 | }; | 
|  | 51 |  | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 52 | struct callchain_list { | 
| Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 53 | u64			ip; | 
| Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 54 | struct map_symbol	ms; | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 55 | struct list_head	list; | 
|  | 56 | }; | 
|  | 57 |  | 
| Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 58 | /* | 
|  | 59 | * A callchain cursor is a single linked list that | 
|  | 60 | * let one feed a callchain progressively. | 
| Masanari Iida | 3fd44cd | 2012-07-18 01:20:59 +0900 | [diff] [blame] | 61 | * It keeps persistent allocated entries to minimize | 
| Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 62 | * allocations. | 
|  | 63 | */ | 
|  | 64 | struct callchain_cursor_node { | 
|  | 65 | u64				ip; | 
|  | 66 | struct map			*map; | 
|  | 67 | struct symbol			*sym; | 
|  | 68 | struct callchain_cursor_node	*next; | 
|  | 69 | }; | 
|  | 70 |  | 
|  | 71 | struct callchain_cursor { | 
|  | 72 | u64				nr; | 
|  | 73 | struct callchain_cursor_node	*first; | 
|  | 74 | struct callchain_cursor_node	**last; | 
|  | 75 | u64				pos; | 
|  | 76 | struct callchain_cursor_node	*curr; | 
|  | 77 | }; | 
|  | 78 |  | 
| Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 79 | extern __thread struct callchain_cursor callchain_cursor; | 
|  | 80 |  | 
| Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 81 | static inline void callchain_init(struct callchain_root *root) | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 82 | { | 
| Frederic Weisbecker | 529363b | 2011-01-14 04:52:01 +0100 | [diff] [blame] | 83 | INIT_LIST_HEAD(&root->node.siblings); | 
| Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 84 | INIT_LIST_HEAD(&root->node.children); | 
|  | 85 | INIT_LIST_HEAD(&root->node.val); | 
| Frederic Weisbecker | 97aa105 | 2010-07-08 06:06:17 +0200 | [diff] [blame] | 86 |  | 
| Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 87 | root->node.parent = NULL; | 
|  | 88 | root->node.hit = 0; | 
| Frederic Weisbecker | 98ee74a | 2010-08-27 02:28:40 +0200 | [diff] [blame] | 89 | root->node.children_hit = 0; | 
| Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 90 | root->max_depth = 0; | 
| Frederic Weisbecker | 8cb76d9 | 2009-06-26 16:28:00 +0200 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
| Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 93 | static inline u64 callchain_cumul_hits(struct callchain_node *node) | 
| Frederic Weisbecker | 1953287b | 2009-08-07 07:11:05 +0200 | [diff] [blame] | 94 | { | 
|  | 95 | return node->hit + node->children_hit; | 
|  | 96 | } | 
|  | 97 |  | 
| Frederic Weisbecker | 16537f1 | 2011-01-14 04:52:00 +0100 | [diff] [blame] | 98 | int callchain_register_param(struct callchain_param *param); | 
| Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 99 | int callchain_append(struct callchain_root *root, | 
|  | 100 | struct callchain_cursor *cursor, | 
|  | 101 | u64 period); | 
|  | 102 |  | 
|  | 103 | int callchain_merge(struct callchain_cursor *cursor, | 
|  | 104 | struct callchain_root *dst, struct callchain_root *src); | 
| Arnaldo Carvalho de Melo | 139633c | 2010-05-09 11:47:13 -0300 | [diff] [blame] | 105 |  | 
| Arnaldo Carvalho de Melo | d20deb6 | 2011-11-25 08:19:45 -0200 | [diff] [blame] | 106 | struct ip_callchain; | 
|  | 107 | union perf_event; | 
|  | 108 |  | 
| Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 109 | bool ip_callchain__valid(struct ip_callchain *chain, | 
|  | 110 | const union perf_event *event); | 
| Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 111 | /* | 
|  | 112 | * Initialize a cursor before adding entries inside, but keep | 
|  | 113 | * the previously allocated entries as a cache. | 
|  | 114 | */ | 
|  | 115 | static inline void callchain_cursor_reset(struct callchain_cursor *cursor) | 
|  | 116 | { | 
|  | 117 | cursor->nr = 0; | 
|  | 118 | cursor->last = &cursor->first; | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, | 
|  | 122 | struct map *map, struct symbol *sym); | 
|  | 123 |  | 
|  | 124 | /* Close a cursor writing session. Initialize for the reader */ | 
|  | 125 | static inline void callchain_cursor_commit(struct callchain_cursor *cursor) | 
|  | 126 | { | 
|  | 127 | cursor->curr = cursor->first; | 
|  | 128 | cursor->pos = 0; | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | /* Cursor reading iteration helpers */ | 
|  | 132 | static inline struct callchain_cursor_node * | 
|  | 133 | callchain_cursor_current(struct callchain_cursor *cursor) | 
|  | 134 | { | 
|  | 135 | if (cursor->pos == cursor->nr) | 
|  | 136 | return NULL; | 
|  | 137 |  | 
|  | 138 | return cursor->curr; | 
|  | 139 | } | 
|  | 140 |  | 
|  | 141 | static inline void callchain_cursor_advance(struct callchain_cursor *cursor) | 
|  | 142 | { | 
|  | 143 | cursor->curr = cursor->curr->next; | 
|  | 144 | cursor->pos++; | 
|  | 145 | } | 
| Arnaldo Carvalho de Melo | 75d9a108 | 2012-12-11 16:46:05 -0300 | [diff] [blame] | 146 |  | 
|  | 147 | struct option; | 
|  | 148 |  | 
|  | 149 | int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset); | 
|  | 150 | extern const char record_callchain_help[]; | 
| John Kacur | 8b40f52 | 2009-09-24 18:02:18 +0200 | [diff] [blame] | 151 | #endif	/* __PERF_CALLCHAIN_H */ |