sort.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 struct sort_entry sort_srcline;
  39. extern enum sort_type sort__first_dimension;
  40. extern const char default_mem_sort_order[];
  41. struct he_stat {
  42. u64 period;
  43. u64 period_sys;
  44. u64 period_us;
  45. u64 period_guest_sys;
  46. u64 period_guest_us;
  47. u64 weight;
  48. u32 nr_events;
  49. };
  50. struct hist_entry_diff {
  51. bool computed;
  52. union {
  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_ops {
  62. void *(*new)(size_t size);
  63. void (*free)(void *ptr);
  64. };
  65. /**
  66. * struct hist_entry - histogram entry
  67. *
  68. * @row_offset - offset from the first callchain expanded to appear on screen
  69. * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
  70. */
  71. struct hist_entry {
  72. struct rb_node rb_node_in;
  73. struct rb_node rb_node;
  74. union {
  75. struct list_head node;
  76. struct list_head head;
  77. } pairs;
  78. struct he_stat stat;
  79. struct he_stat *stat_acc;
  80. struct map_symbol ms;
  81. struct thread *thread;
  82. struct comm *comm;
  83. u64 ip;
  84. u64 transaction;
  85. s32 socket;
  86. s32 cpu;
  87. u8 cpumode;
  88. u8 depth;
  89. /* We are added by hists__add_dummy_entry. */
  90. bool dummy;
  91. bool leaf;
  92. char level;
  93. u8 filtered;
  94. union {
  95. /*
  96. * Since perf diff only supports the stdio output, TUI
  97. * fields are only accessed from perf report (or perf
  98. * top). So make it an union to reduce memory usage.
  99. */
  100. struct hist_entry_diff diff;
  101. struct /* for TUI */ {
  102. u16 row_offset;
  103. u16 nr_rows;
  104. bool init_have_children;
  105. bool unfolded;
  106. bool has_children;
  107. bool has_no_entry;
  108. };
  109. };
  110. char *srcline;
  111. char *srcfile;
  112. struct symbol *parent;
  113. struct branch_info *branch_info;
  114. struct hists *hists;
  115. struct mem_info *mem_info;
  116. void *raw_data;
  117. u32 raw_size;
  118. void *trace_output;
  119. struct perf_hpp_list *hpp_list;
  120. struct hist_entry *parent_he;
  121. struct hist_entry_ops *ops;
  122. union {
  123. /* this is for hierarchical entry structure */
  124. struct {
  125. struct rb_root hroot_in;
  126. struct rb_root hroot_out;
  127. }; /* non-leaf entries */
  128. struct rb_root sorted_chain; /* leaf entry has callchains */
  129. };
  130. struct callchain_root callchain[0]; /* must be last member */
  131. };
  132. static inline bool hist_entry__has_pairs(struct hist_entry *he)
  133. {
  134. return !list_empty(&he->pairs.node);
  135. }
  136. static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
  137. {
  138. if (hist_entry__has_pairs(he))
  139. return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
  140. return NULL;
  141. }
  142. static inline void hist_entry__add_pair(struct hist_entry *pair,
  143. struct hist_entry *he)
  144. {
  145. list_add_tail(&pair->pairs.node, &he->pairs.head);
  146. }
  147. static inline float hist_entry__get_percent_limit(struct hist_entry *he)
  148. {
  149. u64 period = he->stat.period;
  150. u64 total_period = hists__total_period(he->hists);
  151. if (unlikely(total_period == 0))
  152. return 0;
  153. if (symbol_conf.cumulate_callchain)
  154. period = he->stat_acc->period;
  155. return period * 100.0 / total_period;
  156. }
  157. static inline u64 cl_address(u64 address)
  158. {
  159. /* return the cacheline of the address */
  160. return (address & ~(cacheline_size - 1));
  161. }
  162. static inline u64 cl_offset(u64 address)
  163. {
  164. /* return the cacheline of the address */
  165. return (address & (cacheline_size - 1));
  166. }
  167. enum sort_mode {
  168. SORT_MODE__NORMAL,
  169. SORT_MODE__BRANCH,
  170. SORT_MODE__MEMORY,
  171. SORT_MODE__TOP,
  172. SORT_MODE__DIFF,
  173. SORT_MODE__TRACEPOINT,
  174. };
  175. enum sort_type {
  176. /* common sort keys */
  177. SORT_PID,
  178. SORT_COMM,
  179. SORT_DSO,
  180. SORT_SYM,
  181. SORT_PARENT,
  182. SORT_CPU,
  183. SORT_SOCKET,
  184. SORT_SRCLINE,
  185. SORT_SRCFILE,
  186. SORT_LOCAL_WEIGHT,
  187. SORT_GLOBAL_WEIGHT,
  188. SORT_TRANSACTION,
  189. SORT_TRACE,
  190. /* branch stack specific sort keys */
  191. __SORT_BRANCH_STACK,
  192. SORT_DSO_FROM = __SORT_BRANCH_STACK,
  193. SORT_DSO_TO,
  194. SORT_SYM_FROM,
  195. SORT_SYM_TO,
  196. SORT_MISPREDICT,
  197. SORT_ABORT,
  198. SORT_IN_TX,
  199. SORT_CYCLES,
  200. SORT_SRCLINE_FROM,
  201. SORT_SRCLINE_TO,
  202. /* memory mode specific sort keys */
  203. __SORT_MEMORY_MODE,
  204. SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
  205. SORT_MEM_DADDR_DSO,
  206. SORT_MEM_LOCKED,
  207. SORT_MEM_TLB,
  208. SORT_MEM_LVL,
  209. SORT_MEM_SNOOP,
  210. SORT_MEM_DCACHELINE,
  211. SORT_MEM_IADDR_SYMBOL,
  212. };
  213. /*
  214. * configurable sorting bits
  215. */
  216. struct sort_entry {
  217. const char *se_header;
  218. int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
  219. int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
  220. int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
  221. int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
  222. unsigned int width);
  223. int (*se_filter)(struct hist_entry *he, int type, const void *arg);
  224. u8 se_width_idx;
  225. };
  226. extern struct sort_entry sort_thread;
  227. extern struct list_head hist_entry__sort_list;
  228. struct perf_evlist;
  229. struct pevent;
  230. int setup_sorting(struct perf_evlist *evlist);
  231. int setup_output_field(void);
  232. void reset_output_field(void);
  233. void sort__setup_elide(FILE *fp);
  234. void perf_hpp__set_elide(int idx, bool elide);
  235. int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
  236. bool is_strict_order(const char *order);
  237. int hpp_dimension__add_output(unsigned col);
  238. void reset_dimensions(void);
  239. int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
  240. struct perf_evlist *evlist,
  241. int level);
  242. int output_field_add(struct perf_hpp_list *list, char *tok);
  243. int64_t
  244. sort__iaddr_cmp(struct hist_entry *left, struct hist_entry *right);
  245. int64_t
  246. sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right);
  247. int64_t
  248. sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right);
  249. #endif /* __PERF_SORT_H */