perf tools: Update cpumode for each cumulative entry
[linux-2.6/btrfs-unstable.git] / tools / perf / util / callchain.h
blob24a53d562d0a3c970acf362f5fa6b23bab69b067
1 #ifndef __PERF_CALLCHAIN_H
2 #define __PERF_CALLCHAIN_H
4 #include "../perf.h"
5 #include <linux/list.h>
6 #include <linux/rbtree.h>
7 #include "event.h"
8 #include "symbol.h"
10 enum perf_call_graph_mode {
11 CALLCHAIN_NONE,
12 CALLCHAIN_FP,
13 CALLCHAIN_DWARF,
14 CALLCHAIN_MAX
17 enum chain_mode {
18 CHAIN_NONE,
19 CHAIN_FLAT,
20 CHAIN_GRAPH_ABS,
21 CHAIN_GRAPH_REL
24 enum chain_order {
25 ORDER_CALLER,
26 ORDER_CALLEE
29 struct callchain_node {
30 struct callchain_node *parent;
31 struct list_head val;
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 */
36 unsigned int val_nr;
37 u64 hit;
38 u64 children_hit;
41 struct callchain_root {
42 u64 max_depth;
43 struct callchain_node node;
46 struct callchain_param;
48 typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
49 u64, struct callchain_param *);
51 enum chain_key {
52 CCKEY_FUNCTION,
53 CCKEY_ADDRESS
56 struct callchain_param {
57 enum chain_mode mode;
58 u32 print_limit;
59 double min_percent;
60 sort_chain_func_t sort;
61 enum chain_order order;
62 enum chain_key key;
65 struct callchain_list {
66 u64 ip;
67 struct map_symbol ms;
68 struct list_head list;
72 * A callchain cursor is a single linked list that
73 * let one feed a callchain progressively.
74 * It keeps persistent allocated entries to minimize
75 * allocations.
77 struct callchain_cursor_node {
78 u64 ip;
79 struct map *map;
80 struct symbol *sym;
81 struct callchain_cursor_node *next;
84 struct 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;
92 extern __thread struct callchain_cursor callchain_cursor;
94 static inline void callchain_init(struct callchain_root *root)
96 INIT_LIST_HEAD(&root->node.val);
98 root->node.parent = NULL;
99 root->node.hit = 0;
100 root->node.children_hit = 0;
101 root->node.rb_root_in = RB_ROOT;
102 root->max_depth = 0;
105 static inline u64 callchain_cumul_hits(struct callchain_node *node)
107 return node->hit + node->children_hit;
110 int callchain_register_param(struct callchain_param *param);
111 int callchain_append(struct callchain_root *root,
112 struct callchain_cursor *cursor,
113 u64 period);
115 int callchain_merge(struct callchain_cursor *cursor,
116 struct callchain_root *dst, struct callchain_root *src);
119 * Initialize a cursor before adding entries inside, but keep
120 * the previously allocated entries as a cache.
122 static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
124 cursor->nr = 0;
125 cursor->last = &cursor->first;
128 int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
129 struct map *map, struct symbol *sym);
131 /* Close a cursor writing session. Initialize for the reader */
132 static inline void callchain_cursor_commit(struct callchain_cursor *cursor)
134 cursor->curr = cursor->first;
135 cursor->pos = 0;
138 /* Cursor reading iteration helpers */
139 static inline struct callchain_cursor_node *
140 callchain_cursor_current(struct callchain_cursor *cursor)
142 if (cursor->pos == cursor->nr)
143 return NULL;
145 return cursor->curr;
148 static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
150 cursor->curr = cursor->curr->next;
151 cursor->pos++;
154 struct option;
155 struct hist_entry;
157 int record_parse_callchain(const char *arg, struct record_opts *opts);
158 int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
159 int record_callchain_opt(const struct option *opt, const char *arg, int unset);
161 int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
162 struct perf_evsel *evsel, struct addr_location *al,
163 int max_stack);
164 int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sample);
165 int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node,
166 bool hide_unresolved);
168 extern const char record_callchain_help[];
169 int parse_callchain_report_opt(const char *arg);
170 #endif /* __PERF_CALLCHAIN_H */