sort.h 5.3 KB

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