perf tools: Move perf_call_graph_mode enum from perf.h
[deliverable/linux.git] / tools / perf / util / callchain.h
CommitLineData
8cb76d99
FW
1#ifndef __PERF_CALLCHAIN_H
2#define __PERF_CALLCHAIN_H
3
4#include "../perf.h"
5da50258 5#include <linux/list.h>
43cbcd8a 6#include <linux/rbtree.h>
139633c6 7#include "event.h"
4424961a 8#include "symbol.h"
8cb76d99 9
2c83bc08
JO
10enum perf_call_graph_mode {
11 CALLCHAIN_NONE,
12 CALLCHAIN_FP,
13 CALLCHAIN_DWARF,
14 CALLCHAIN_MAX
15};
16
4eb3e478 17enum chain_mode {
b1a88349 18 CHAIN_NONE,
805d127d
FW
19 CHAIN_FLAT,
20 CHAIN_GRAPH_ABS,
21 CHAIN_GRAPH_REL
4eb3e478 22};
8cb76d99 23
d797fdc5
SL
24enum chain_order {
25 ORDER_CALLER,
26 ORDER_CALLEE
27};
28
8cb76d99
FW
29struct callchain_node {
30 struct callchain_node *parent;
f37a291c 31 struct list_head val;
e369517c
NK
32 struct rb_node rb_node_in; /* to insert nodes in an rbtree */
33 struct rb_node rb_node; /* to sort nodes in an output tree */
34 struct rb_root rb_root_in; /* input tree of children */
35 struct rb_root rb_root; /* sorted output tree of children */
f37a291c
IM
36 unsigned int val_nr;
37 u64 hit;
1953287b 38 u64 children_hit;
8cb76d99
FW
39};
40
d2009c51
FW
41struct callchain_root {
42 u64 max_depth;
43 struct callchain_node node;
44};
45
805d127d
FW
46struct callchain_param;
47
d2009c51 48typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
805d127d
FW
49 u64, struct callchain_param *);
50
99571ab3
AK
51enum chain_key {
52 CCKEY_FUNCTION,
53 CCKEY_ADDRESS
54};
55
805d127d
FW
56struct callchain_param {
57 enum chain_mode mode;
232a5c94 58 u32 print_limit;
805d127d
FW
59 double min_percent;
60 sort_chain_func_t sort;
d797fdc5 61 enum chain_order order;
99571ab3 62 enum chain_key key;
805d127d
FW
63};
64
8cb76d99 65struct callchain_list {
f37a291c 66 u64 ip;
b3c9ac08 67 struct map_symbol ms;
8cb76d99
FW
68 struct list_head list;
69};
70
1b3a0e95
FW
71/*
72 * A callchain cursor is a single linked list that
73 * let one feed a callchain progressively.
3fd44cd4 74 * It keeps persistent allocated entries to minimize
1b3a0e95
FW
75 * allocations.
76 */
77struct callchain_cursor_node {
78 u64 ip;
79 struct map *map;
80 struct symbol *sym;
81 struct callchain_cursor_node *next;
82};
83
84struct callchain_cursor {
85 u64 nr;
86 struct callchain_cursor_node *first;
87 struct callchain_cursor_node **last;
88 u64 pos;
89 struct callchain_cursor_node *curr;
90};
91
47260645
NK
92extern __thread struct callchain_cursor callchain_cursor;
93
d2009c51 94static inline void callchain_init(struct callchain_root *root)
8cb76d99 95{
d2009c51 96 INIT_LIST_HEAD(&root->node.val);
97aa1052 97
d2009c51
FW
98 root->node.parent = NULL;
99 root->node.hit = 0;
98ee74a7 100 root->node.children_hit = 0;
e369517c 101 root->node.rb_root_in = RB_ROOT;
d2009c51 102 root->max_depth = 0;
8cb76d99
FW
103}
104
f08c3154 105static inline u64 callchain_cumul_hits(struct callchain_node *node)
1953287b
FW
106{
107 return node->hit + node->children_hit;
108}
109
16537f13 110int callchain_register_param(struct callchain_param *param);
1b3a0e95
FW
111int callchain_append(struct callchain_root *root,
112 struct callchain_cursor *cursor,
113 u64 period);
114
115int callchain_merge(struct callchain_cursor *cursor,
116 struct callchain_root *dst, struct callchain_root *src);
139633c6 117
1b3a0e95
FW
118/*
119 * Initialize a cursor before adding entries inside, but keep
120 * the previously allocated entries as a cache.
121 */
122static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
123{
124 cursor->nr = 0;
125 cursor->last = &cursor->first;
126}
127
128int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
129 struct map *map, struct symbol *sym);
130
131/* Close a cursor writing session. Initialize for the reader */
132static inline void callchain_cursor_commit(struct callchain_cursor *cursor)
133{
134 cursor->curr = cursor->first;
135 cursor->pos = 0;
136}
137
138/* Cursor reading iteration helpers */
139static inline struct callchain_cursor_node *
140callchain_cursor_current(struct callchain_cursor *cursor)
141{
142 if (cursor->pos == cursor->nr)
143 return NULL;
144
145 return cursor->curr;
146}
147
148static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
149{
150 cursor->curr = cursor->curr->next;
151 cursor->pos++;
152}
75d9a108
ACM
153
154struct option;
2dc9fb1a 155struct hist_entry;
75d9a108 156
b4006796 157int record_parse_callchain(const char *arg, struct record_opts *opts);
75d9a108 158int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
09b0fd45
JO
159int record_callchain_opt(const struct option *opt, const char *arg, int unset);
160
2dc9fb1a
NK
161int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
162 struct perf_evsel *evsel, struct addr_location *al,
163 int max_stack);
164int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);
165
75d9a108 166extern const char record_callchain_help[];
cff6bb46 167int parse_callchain_report_opt(const char *arg);
8b40f521 168#endif /* __PERF_CALLCHAIN_H */
This page took 0.179521 seconds and 5 git commands to generate.