blob: 43cf3ea9e088fd86953637450036ecb56f3964fd [file] [log] [blame]
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +02001#ifndef __PERF_CALLCHAIN_H
2#define __PERF_CALLCHAIN_H
3
4#include "../perf.h"
Arnaldo Carvalho de Melo5da50252009-07-01 14:46:08 -03005#include <linux/list.h>
Arnaldo Carvalho de Melo43cbcd82009-07-01 12:28:37 -03006#include <linux/rbtree.h>
Frederic Weisbecker66e274f2009-08-12 11:07:25 +02007#include "util.h"
Frederic Weisbecker44249612009-07-01 05:35:14 +02008#include "symbol.h"
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +02009
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +020010enum chain_mode {
Frederic Weisbeckerb1a88342009-08-08 02:16:24 +020011 CHAIN_NONE,
Frederic Weisbecker805d1272009-07-05 07:39:21 +020012 CHAIN_FLAT,
13 CHAIN_GRAPH_ABS,
14 CHAIN_GRAPH_REL
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +020015};
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +020016
17struct callchain_node {
18 struct callchain_node *parent;
19 struct list_head brothers;
Ingo Molnarf37a2912009-07-01 12:37:06 +020020 struct list_head children;
21 struct list_head val;
Frederic Weisbecker4eb3e472009-07-02 17:58:21 +020022 struct rb_node rb_node; /* to sort nodes in an rbtree */
23 struct rb_root rb_root; /* sorted tree of children */
Ingo Molnarf37a2912009-07-01 12:37:06 +020024 unsigned int val_nr;
25 u64 hit;
Frederic Weisbecker19532872009-08-07 07:11:05 +020026 u64 children_hit;
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +020027};
28
Frederic Weisbecker805d1272009-07-05 07:39:21 +020029struct callchain_param;
30
31typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_node *,
32 u64, struct callchain_param *);
33
34struct callchain_param {
35 enum chain_mode mode;
36 double min_percent;
37 sort_chain_func_t sort;
38};
39
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +020040struct callchain_list {
Ingo Molnarf37a2912009-07-01 12:37:06 +020041 u64 ip;
Frederic Weisbecker44249612009-07-01 05:35:14 +020042 struct symbol *sym;
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +020043 struct list_head list;
44};
45
46static inline void callchain_init(struct callchain_node *node)
47{
48 INIT_LIST_HEAD(&node->brothers);
49 INIT_LIST_HEAD(&node->children);
50 INIT_LIST_HEAD(&node->val);
51}
52
Frederic Weisbecker19532872009-08-07 07:11:05 +020053static inline u64 cumul_hits(struct callchain_node *node)
54{
55 return node->hit + node->children_hit;
56}
57
Frederic Weisbecker805d1272009-07-05 07:39:21 +020058int register_callchain_param(struct callchain_param *param);
Frederic Weisbecker44249612009-07-01 05:35:14 +020059void append_chain(struct callchain_node *root, struct ip_callchain *chain,
60 struct symbol **syms);
Frederic Weisbecker8cb76d92009-06-26 16:28:00 +020061#endif