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