sort.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. extern const char default_mem_sort_order[];
  43. struct he_stat {
  44. u64 period;
  45. u64 period_sys;
  46. u64 period_us;
  47. u64 period_guest_sys;
  48. u64 period_guest_us;
  49. u64 weight;
  50. u32 nr_events;
  51. };
  52. struct hist_entry_diff {
  53. bool computed;
  54. union {
  55. /* PERF_HPP__DELTA */
  56. double period_ratio_delta;
  57. /* PERF_HPP__RATIO */
  58. double period_ratio;
  59. /* HISTC_WEIGHTED_DIFF */
  60. s64 wdiff;
  61. };
  62. };
  63. /**
  64. * struct hist_entry - histogram entry
  65. *
  66. * @row_offset - offset from the first callchain expanded to appear on screen
  67. * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
  68. */
  69. struct hist_entry {
  70. struct rb_node rb_node_in;
  71. struct rb_node rb_node;
  72. union {
  73. struct list_head node;
  74. struct list_head head;
  75. } pairs;
  76. struct he_stat stat;
  77. struct he_stat *stat_acc;
  78. struct map_symbol ms;
  79. struct thread *thread;
  80. struct comm *comm;
  81. u64 ip;
  82. u64 transaction;
  83. s32 cpu;
  84. u8 cpumode;
  85. /* We are added by hists__add_dummy_entry. */
  86. bool dummy;
  87. char level;
  88. u8 filtered;
  89. union {
  90. /*
  91. * Since perf diff only supports the stdio output, TUI
  92. * fields are only accessed from perf report (or perf
  93. * top). So make it an union to reduce memory usage.
  94. */
  95. struct hist_entry_diff diff;
  96. struct /* for TUI */ {
  97. u16 row_offset;
  98. u16 nr_rows;
  99. bool init_have_children;
  100. bool unfolded;
  101. bool has_children;
  102. };
  103. };
  104. char *srcline;
  105. char *srcfile;
  106. struct symbol *parent;
  107. struct rb_root sorted_chain;
  108. struct branch_info *branch_info;
  109. struct hists *hists;
  110. struct mem_info *mem_info;
  111. struct callchain_root callchain[0]; /* must be last member */
  112. };
  113. static inline bool hist_entry__has_pairs(struct hist_entry *he)
  114. {
  115. return !list_empty(&he->pairs.node);
  116. }
  117. static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
  118. {
  119. if (hist_entry__has_pairs(he))
  120. return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
  121. return NULL;
  122. }
  123. static inline void hist_entry__add_pair(struct hist_entry *pair,
  124. struct hist_entry *he)
  125. {
  126. list_add_tail(&pair->pairs.node, &he->pairs.head);
  127. }
  128. static inline float hist_entry__get_percent_limit(struct hist_entry *he)
  129. {
  130. u64 period = he->stat.period;
  131. u64 total_period = hists__total_period(he->hists);
  132. if (unlikely(total_period == 0))
  133. return 0;
  134. if (symbol_conf.cumulate_callchain)
  135. period = he->stat_acc->period;
  136. return period * 100.0 / total_period;
  137. }
  138. enum sort_mode {
  139. SORT_MODE__NORMAL,
  140. SORT_MODE__BRANCH,
  141. SORT_MODE__MEMORY,
  142. SORT_MODE__TOP,
  143. SORT_MODE__DIFF,
  144. };
  145. enum sort_type {
  146. /* common sort keys */
  147. SORT_PID,
  148. SORT_COMM,
  149. SORT_DSO,
  150. SORT_SYM,
  151. SORT_PARENT,
  152. SORT_CPU,
  153. SORT_SRCLINE,
  154. SORT_SRCFILE,
  155. SORT_LOCAL_WEIGHT,
  156. SORT_GLOBAL_WEIGHT,
  157. SORT_TRANSACTION,
  158. /* branch stack specific sort keys */
  159. __SORT_BRANCH_STACK,
  160. SORT_DSO_FROM = __SORT_BRANCH_STACK,
  161. SORT_DSO_TO,
  162. SORT_SYM_FROM,
  163. SORT_SYM_TO,
  164. SORT_MISPREDICT,
  165. SORT_ABORT,
  166. SORT_IN_TX,
  167. SORT_CYCLES,
  168. /* memory mode specific sort keys */
  169. __SORT_MEMORY_MODE,
  170. SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
  171. SORT_MEM_DADDR_DSO,
  172. SORT_MEM_LOCKED,
  173. SORT_MEM_TLB,
  174. SORT_MEM_LVL,
  175. SORT_MEM_SNOOP,
  176. SORT_MEM_DCACHELINE,
  177. };
  178. /*
  179. * configurable sorting bits
  180. */
  181. struct sort_entry {
  182. struct list_head list;
  183. const char *se_header;
  184. int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
  185. int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
  186. int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
  187. int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
  188. unsigned int width);
  189. u8 se_width_idx;
  190. };
  191. extern struct sort_entry sort_thread;
  192. extern struct list_head hist_entry__sort_list;
  193. int setup_sorting(void);
  194. int setup_output_field(void);
  195. void reset_output_field(void);
  196. extern int sort_dimension__add(const char *);
  197. void sort__setup_elide(FILE *fp);
  198. void perf_hpp__set_elide(int idx, bool elide);
  199. int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
  200. bool is_strict_order(const char *order);
  201. #endif /* __PERF_SORT_H */