callchain.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef __PERF_CALLCHAIN_H
  2. #define __PERF_CALLCHAIN_H
  3. #include "../perf.h"
  4. #include <linux/list.h>
  5. #include <linux/rbtree.h>
  6. #include "event.h"
  7. #include "symbol.h"
  8. enum chain_mode {
  9. CHAIN_NONE,
  10. CHAIN_FLAT,
  11. CHAIN_GRAPH_ABS,
  12. CHAIN_GRAPH_REL
  13. };
  14. struct callchain_node {
  15. struct callchain_node *parent;
  16. struct list_head brothers;
  17. struct list_head children;
  18. struct list_head val;
  19. struct rb_node rb_node; /* to sort nodes in an rbtree */
  20. struct rb_root rb_root; /* sorted tree of children */
  21. unsigned int val_nr;
  22. u64 hit;
  23. u64 children_hit;
  24. };
  25. struct callchain_root {
  26. u64 max_depth;
  27. struct callchain_node node;
  28. };
  29. struct callchain_param;
  30. typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_root *,
  31. u64, struct callchain_param *);
  32. struct callchain_param {
  33. enum chain_mode mode;
  34. u32 print_limit;
  35. double min_percent;
  36. sort_chain_func_t sort;
  37. };
  38. struct callchain_list {
  39. u64 ip;
  40. struct map_symbol ms;
  41. struct list_head list;
  42. };
  43. static inline void callchain_init(struct callchain_root *root)
  44. {
  45. INIT_LIST_HEAD(&root->node.brothers);
  46. INIT_LIST_HEAD(&root->node.children);
  47. INIT_LIST_HEAD(&root->node.val);
  48. root->node.parent = NULL;
  49. root->node.hit = 0;
  50. root->node.children_hit = 0;
  51. root->max_depth = 0;
  52. }
  53. static inline u64 cumul_hits(struct callchain_node *node)
  54. {
  55. return node->hit + node->children_hit;
  56. }
  57. int register_callchain_param(struct callchain_param *param);
  58. int callchain_append(struct callchain_root *root, struct ip_callchain *chain,
  59. struct map_symbol *syms, u64 period);
  60. int callchain_merge(struct callchain_root *dst, struct callchain_root *src);
  61. bool ip_callchain__valid(struct ip_callchain *chain, const event_t *event);
  62. #endif /* __PERF_CALLCHAIN_H */