sort.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef __PERF_SORT_H
  2. #define __PERF_SORT_H
  3. #include "../builtin.h"
  4. #include "util.h"
  5. #include "color.h"
  6. #include <linux/list.h>
  7. #include "cache.h"
  8. #include <linux/rbtree.h>
  9. #include "symbol.h"
  10. #include "string.h"
  11. #include "callchain.h"
  12. #include "strlist.h"
  13. #include "values.h"
  14. #include "../perf.h"
  15. #include "debug.h"
  16. #include "header.h"
  17. #include "parse-options.h"
  18. #include "parse-events.h"
  19. #include "thread.h"
  20. extern regex_t parent_regex;
  21. extern const char *sort_order;
  22. extern const char default_parent_pattern[];
  23. extern const char *parent_pattern;
  24. extern const char default_sort_order[];
  25. extern regex_t ignore_callees_regex;
  26. extern int have_ignore_callees;
  27. extern int sort__need_collapse;
  28. extern int sort__has_parent;
  29. extern int sort__has_sym;
  30. extern enum sort_mode sort__mode;
  31. extern struct sort_entry sort_comm;
  32. extern struct sort_entry sort_dso;
  33. extern struct sort_entry sort_sym;
  34. extern struct sort_entry sort_parent;
  35. extern struct sort_entry sort_dso_from;
  36. extern struct sort_entry sort_dso_to;
  37. extern struct sort_entry sort_sym_from;
  38. extern struct sort_entry sort_sym_to;
  39. extern enum sort_type sort__first_dimension;
  40. struct he_stat {
  41. u64 period;
  42. u64 period_sys;
  43. u64 period_us;
  44. u64 period_guest_sys;
  45. u64 period_guest_us;
  46. u64 weight;
  47. u32 nr_events;
  48. };
  49. struct hist_entry_diff {
  50. bool computed;
  51. /* PERF_HPP__DELTA */
  52. double period_ratio_delta;
  53. /* PERF_HPP__RATIO */
  54. double period_ratio;
  55. /* HISTC_WEIGHTED_DIFF */
  56. s64 wdiff;
  57. };
  58. /**
  59. * struct hist_entry - histogram entry
  60. *
  61. * @row_offset - offset from the first callchain expanded to appear on screen
  62. * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
  63. */
  64. struct hist_entry {
  65. struct rb_node rb_node_in;
  66. struct rb_node rb_node;
  67. union {
  68. struct list_head node;
  69. struct list_head head;
  70. } pairs;
  71. struct he_stat stat;
  72. struct map_symbol ms;
  73. struct thread *thread;
  74. struct comm *comm;
  75. u64 ip;
  76. u64 transaction;
  77. s32 cpu;
  78. struct hist_entry_diff diff;
  79. /* We are added by hists__add_dummy_entry. */
  80. bool dummy;
  81. /* XXX These two should move to some tree widget lib */
  82. u16 row_offset;
  83. u16 nr_rows;
  84. bool init_have_children;
  85. char level;
  86. bool used;
  87. u8 filtered;
  88. char *srcline;
  89. struct symbol *parent;
  90. unsigned long position;
  91. struct rb_root sorted_chain;
  92. struct branch_info *branch_info;
  93. struct hists *hists;
  94. struct mem_info *mem_info;
  95. struct callchain_root callchain[0]; /* must be last member */
  96. };
  97. static inline bool hist_entry__has_pairs(struct hist_entry *he)
  98. {
  99. return !list_empty(&he->pairs.node);
  100. }
  101. static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
  102. {
  103. if (hist_entry__has_pairs(he))
  104. return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
  105. return NULL;
  106. }
  107. static inline void hist_entry__add_pair(struct hist_entry *pair,
  108. struct hist_entry *he)
  109. {
  110. list_add_tail(&pair->pairs.node, &he->pairs.head);
  111. }
  112. enum sort_mode {
  113. SORT_MODE__NORMAL,
  114. SORT_MODE__BRANCH,
  115. SORT_MODE__MEMORY,
  116. };
  117. enum sort_type {
  118. /* common sort keys */
  119. SORT_PID,
  120. SORT_COMM,
  121. SORT_DSO,
  122. SORT_SYM,
  123. SORT_PARENT,
  124. SORT_CPU,
  125. SORT_SRCLINE,
  126. SORT_LOCAL_WEIGHT,
  127. SORT_GLOBAL_WEIGHT,
  128. SORT_TRANSACTION,
  129. /* branch stack specific sort keys */
  130. __SORT_BRANCH_STACK,
  131. SORT_DSO_FROM = __SORT_BRANCH_STACK,
  132. SORT_DSO_TO,
  133. SORT_SYM_FROM,
  134. SORT_SYM_TO,
  135. SORT_MISPREDICT,
  136. SORT_ABORT,
  137. SORT_IN_TX,
  138. /* memory mode specific sort keys */
  139. __SORT_MEMORY_MODE,
  140. SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
  141. SORT_MEM_DADDR_DSO,
  142. SORT_MEM_LOCKED,
  143. SORT_MEM_TLB,
  144. SORT_MEM_LVL,
  145. SORT_MEM_SNOOP,
  146. };
  147. /*
  148. * configurable sorting bits
  149. */
  150. struct sort_entry {
  151. struct list_head list;
  152. const char *se_header;
  153. int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
  154. int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
  155. int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
  156. unsigned int width);
  157. u8 se_width_idx;
  158. bool elide;
  159. };
  160. extern struct sort_entry sort_thread;
  161. extern struct list_head hist_entry__sort_list;
  162. int setup_sorting(void);
  163. extern int sort_dimension__add(const char *);
  164. void sort__setup_elide(FILE *fp);
  165. int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
  166. #endif /* __PERF_SORT_H */