sort.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 <subcmd/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 enum sort_mode sort__mode;
  30. extern struct sort_entry sort_comm;
  31. extern struct sort_entry sort_dso;
  32. extern struct sort_entry sort_sym;
  33. extern struct sort_entry sort_parent;
  34. extern struct sort_entry sort_dso_from;
  35. extern struct sort_entry sort_dso_to;
  36. extern struct sort_entry sort_sym_from;
  37. extern struct sort_entry sort_sym_to;
  38. extern enum sort_type sort__first_dimension;
  39. extern const char default_mem_sort_order[];
  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. union {
  52. /* PERF_HPP__DELTA */
  53. double period_ratio_delta;
  54. /* PERF_HPP__RATIO */
  55. double period_ratio;
  56. /* HISTC_WEIGHTED_DIFF */
  57. s64 wdiff;
  58. };
  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 socket;
  81. s32 cpu;
  82. u8 cpumode;
  83. u8 depth;
  84. /* We are added by hists__add_dummy_entry. */
  85. bool dummy;
  86. bool leaf;
  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. bool has_no_entry;
  103. };
  104. };
  105. char *srcline;
  106. char *srcfile;
  107. struct symbol *parent;
  108. struct branch_info *branch_info;
  109. struct hists *hists;
  110. struct mem_info *mem_info;
  111. void *raw_data;
  112. u32 raw_size;
  113. void *trace_output;
  114. struct perf_hpp_list *hpp_list;
  115. struct hist_entry *parent_he;
  116. union {
  117. /* this is for hierarchical entry structure */
  118. struct {
  119. struct rb_root hroot_in;
  120. struct rb_root hroot_out;
  121. }; /* non-leaf entries */
  122. struct rb_root sorted_chain; /* leaf entry has callchains */
  123. };
  124. struct callchain_root callchain[0]; /* must be last member */
  125. };
  126. static inline bool hist_entry__has_pairs(struct hist_entry *he)
  127. {
  128. return !list_empty(&he->pairs.node);
  129. }
  130. static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
  131. {
  132. if (hist_entry__has_pairs(he))
  133. return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
  134. return NULL;
  135. }
  136. static inline void hist_entry__add_pair(struct hist_entry *pair,
  137. struct hist_entry *he)
  138. {
  139. list_add_tail(&pair->pairs.node, &he->pairs.head);
  140. }
  141. static inline float hist_entry__get_percent_limit(struct hist_entry *he)
  142. {
  143. u64 period = he->stat.period;
  144. u64 total_period = hists__total_period(he->hists);
  145. if (unlikely(total_period == 0))
  146. return 0;
  147. if (symbol_conf.cumulate_callchain)
  148. period = he->stat_acc->period;
  149. return period * 100.0 / total_period;
  150. }
  151. static inline u64 cl_address(u64 address)
  152. {
  153. /* return the cacheline of the address */
  154. return (address & ~(cacheline_size - 1));
  155. }
  156. static inline u64 cl_offset(u64 address)
  157. {
  158. /* return the cacheline of the address */
  159. return (address & (cacheline_size - 1));
  160. }
  161. enum sort_mode {
  162. SORT_MODE__NORMAL,
  163. SORT_MODE__BRANCH,
  164. SORT_MODE__MEMORY,
  165. SORT_MODE__TOP,
  166. SORT_MODE__DIFF,
  167. SORT_MODE__TRACEPOINT,
  168. };
  169. enum sort_type {
  170. /* common sort keys */
  171. SORT_PID,
  172. SORT_COMM,
  173. SORT_DSO,
  174. SORT_SYM,
  175. SORT_PARENT,
  176. SORT_CPU,
  177. SORT_SOCKET,
  178. SORT_SRCLINE,
  179. SORT_SRCFILE,
  180. SORT_LOCAL_WEIGHT,
  181. SORT_GLOBAL_WEIGHT,
  182. SORT_TRANSACTION,
  183. SORT_TRACE,
  184. /* branch stack specific sort keys */
  185. __SORT_BRANCH_STACK,
  186. SORT_DSO_FROM = __SORT_BRANCH_STACK,
  187. SORT_DSO_TO,
  188. SORT_SYM_FROM,
  189. SORT_SYM_TO,
  190. SORT_MISPREDICT,
  191. SORT_ABORT,
  192. SORT_IN_TX,
  193. SORT_CYCLES,
  194. SORT_SRCLINE_FROM,
  195. SORT_SRCLINE_TO,
  196. /* memory mode specific sort keys */
  197. __SORT_MEMORY_MODE,
  198. SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
  199. SORT_MEM_DADDR_DSO,
  200. SORT_MEM_LOCKED,
  201. SORT_MEM_TLB,
  202. SORT_MEM_LVL,
  203. SORT_MEM_SNOOP,
  204. SORT_MEM_DCACHELINE,
  205. SORT_MEM_IADDR_SYMBOL,
  206. };
  207. /*
  208. * configurable sorting bits
  209. */
  210. struct sort_entry {
  211. const char *se_header;
  212. int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
  213. int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
  214. int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
  215. int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
  216. unsigned int width);
  217. int (*se_filter)(struct hist_entry *he, int type, const void *arg);
  218. u8 se_width_idx;
  219. };
  220. extern struct sort_entry sort_thread;
  221. extern struct list_head hist_entry__sort_list;
  222. struct perf_evlist;
  223. struct pevent;
  224. int setup_sorting(struct perf_evlist *evlist);
  225. int setup_output_field(void);
  226. void reset_output_field(void);
  227. void sort__setup_elide(FILE *fp);
  228. void perf_hpp__set_elide(int idx, bool elide);
  229. int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
  230. bool is_strict_order(const char *order);
  231. int hpp_dimension__add_output(unsigned col);
  232. #endif /* __PERF_SORT_H */