sort.h 4.8 KB

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