sort.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_SORT_H
  3. #define __PERF_SORT_H
  4. #include <regex.h>
  5. #include <stdbool.h>
  6. #include <linux/list.h>
  7. #include <linux/rbtree.h>
  8. #include "map_symbol.h"
  9. #include "symbol_conf.h"
  10. #include "callchain.h"
  11. #include "values.h"
  12. #include "hist.h"
  13. #include "stat.h"
  14. #include "spark.h"
  15. struct option;
  16. struct thread;
  17. extern regex_t parent_regex;
  18. extern const char *sort_order;
  19. extern const char *field_order;
  20. extern const char default_parent_pattern[];
  21. extern const char *parent_pattern;
  22. extern const char *default_sort_order;
  23. extern regex_t ignore_callees_regex;
  24. extern int have_ignore_callees;
  25. extern enum sort_mode sort__mode;
  26. extern struct sort_entry sort_comm;
  27. extern struct sort_entry sort_dso;
  28. extern struct sort_entry sort_sym;
  29. extern struct sort_entry sort_parent;
  30. extern struct sort_entry sort_dso_from;
  31. extern struct sort_entry sort_dso_to;
  32. extern struct sort_entry sort_sym_from;
  33. extern struct sort_entry sort_sym_to;
  34. extern struct sort_entry sort_srcline;
  35. extern enum sort_type sort__first_dimension;
  36. extern const char default_mem_sort_order[];
  37. struct res_sample {
  38. u64 time;
  39. int cpu;
  40. int tid;
  41. };
  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 namespace_id {
  52. u64 dev;
  53. u64 ino;
  54. };
  55. struct hist_entry_diff {
  56. bool computed;
  57. union {
  58. /* PERF_HPP__DELTA */
  59. double period_ratio_delta;
  60. /* PERF_HPP__RATIO */
  61. double period_ratio;
  62. /* HISTC_WEIGHTED_DIFF */
  63. s64 wdiff;
  64. /* PERF_HPP_DIFF__CYCLES */
  65. s64 cycles;
  66. };
  67. struct stats stats;
  68. unsigned long svals[NUM_SPARKS];
  69. };
  70. struct hist_entry_ops {
  71. void *(*new)(size_t size);
  72. void (*free)(void *ptr);
  73. };
  74. /**
  75. * struct hist_entry - histogram entry
  76. *
  77. * @row_offset - offset from the first callchain expanded to appear on screen
  78. * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
  79. */
  80. struct hist_entry {
  81. struct rb_node rb_node_in;
  82. struct rb_node rb_node;
  83. union {
  84. struct list_head node;
  85. struct list_head head;
  86. } pairs;
  87. struct he_stat stat;
  88. struct he_stat *stat_acc;
  89. struct map_symbol ms;
  90. struct thread *thread;
  91. struct comm *comm;
  92. struct namespace_id cgroup_id;
  93. u64 cgroup;
  94. u64 ip;
  95. u64 transaction;
  96. s32 socket;
  97. s32 cpu;
  98. u8 cpumode;
  99. u8 depth;
  100. /* We are added by hists__add_dummy_entry. */
  101. bool dummy;
  102. bool leaf;
  103. char level;
  104. u8 filtered;
  105. u16 callchain_size;
  106. union {
  107. /*
  108. * Since perf diff only supports the stdio output, TUI
  109. * fields are only accessed from perf report (or perf
  110. * top). So make it a union to reduce memory usage.
  111. */
  112. struct hist_entry_diff diff;
  113. struct /* for TUI */ {
  114. u16 row_offset;
  115. u16 nr_rows;
  116. bool init_have_children;
  117. bool unfolded;
  118. bool has_children;
  119. bool has_no_entry;
  120. };
  121. };
  122. char *srcline;
  123. char *srcfile;
  124. struct symbol *parent;
  125. struct branch_info *branch_info;
  126. long time;
  127. struct hists *hists;
  128. struct mem_info *mem_info;
  129. struct block_info *block_info;
  130. void *raw_data;
  131. u32 raw_size;
  132. int num_res;
  133. struct res_sample *res_samples;
  134. void *trace_output;
  135. struct perf_hpp_list *hpp_list;
  136. struct hist_entry *parent_he;
  137. struct hist_entry_ops *ops;
  138. union {
  139. /* this is for hierarchical entry structure */
  140. struct {
  141. struct rb_root_cached hroot_in;
  142. struct rb_root_cached hroot_out;
  143. }; /* non-leaf entries */
  144. struct rb_root sorted_chain; /* leaf entry has callchains */
  145. };
  146. struct callchain_root callchain[0]; /* must be last member */
  147. };
  148. static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
  149. {
  150. return he->callchain_size != 0;
  151. }
  152. int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width);
  153. static inline bool hist_entry__has_pairs(struct hist_entry *he)
  154. {
  155. return !list_empty(&he->pairs.node);
  156. }
  157. static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
  158. {
  159. if (hist_entry__has_pairs(he))
  160. return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
  161. return NULL;
  162. }
  163. static inline void hist_entry__add_pair(struct hist_entry *pair,
  164. struct hist_entry *he)
  165. {
  166. list_add_tail(&pair->pairs.node, &he->pairs.head);
  167. }
  168. static inline float hist_entry__get_percent_limit(struct hist_entry *he)
  169. {
  170. u64 period = he->stat.period;
  171. u64 total_period = hists__total_period(he->hists);
  172. if (unlikely(total_period == 0))
  173. return 0;
  174. if (symbol_conf.cumulate_callchain)
  175. period = he->stat_acc->period;
  176. return period * 100.0 / total_period;
  177. }
  178. enum sort_mode {
  179. SORT_MODE__NORMAL,
  180. SORT_MODE__BRANCH,
  181. SORT_MODE__MEMORY,
  182. SORT_MODE__TOP,
  183. SORT_MODE__DIFF,
  184. SORT_MODE__TRACEPOINT,
  185. };
  186. enum sort_type {
  187. /* common sort keys */
  188. SORT_PID,
  189. SORT_COMM,
  190. SORT_DSO,
  191. SORT_SYM,
  192. SORT_PARENT,
  193. SORT_CPU,
  194. SORT_SOCKET,
  195. SORT_SRCLINE,
  196. SORT_SRCFILE,
  197. SORT_LOCAL_WEIGHT,
  198. SORT_GLOBAL_WEIGHT,
  199. SORT_TRANSACTION,
  200. SORT_TRACE,
  201. SORT_SYM_SIZE,
  202. SORT_DSO_SIZE,
  203. SORT_CGROUP,
  204. SORT_CGROUP_ID,
  205. SORT_SYM_IPC_NULL,
  206. SORT_TIME,
  207. /* branch stack specific sort keys */
  208. __SORT_BRANCH_STACK,
  209. SORT_DSO_FROM = __SORT_BRANCH_STACK,
  210. SORT_DSO_TO,
  211. SORT_SYM_FROM,
  212. SORT_SYM_TO,
  213. SORT_MISPREDICT,
  214. SORT_ABORT,
  215. SORT_IN_TX,
  216. SORT_CYCLES,
  217. SORT_SRCLINE_FROM,
  218. SORT_SRCLINE_TO,
  219. SORT_SYM_IPC,
  220. /* memory mode specific sort keys */
  221. __SORT_MEMORY_MODE,
  222. SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
  223. SORT_MEM_DADDR_DSO,
  224. SORT_MEM_LOCKED,
  225. SORT_MEM_TLB,
  226. SORT_MEM_LVL,
  227. SORT_MEM_SNOOP,
  228. SORT_MEM_DCACHELINE,
  229. SORT_MEM_IADDR_SYMBOL,
  230. SORT_MEM_PHYS_DADDR,
  231. };
  232. /*
  233. * configurable sorting bits
  234. */
  235. struct sort_entry {
  236. const char *se_header;
  237. int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
  238. int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
  239. int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
  240. int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
  241. unsigned int width);
  242. int (*se_filter)(struct hist_entry *he, int type, const void *arg);
  243. u8 se_width_idx;
  244. };
  245. struct block_hist {
  246. struct hists block_hists;
  247. struct perf_hpp_list block_list;
  248. struct perf_hpp_fmt block_fmt;
  249. int block_idx;
  250. bool valid;
  251. struct hist_entry he;
  252. };
  253. extern struct sort_entry sort_thread;
  254. extern struct list_head hist_entry__sort_list;
  255. struct evlist;
  256. struct tep_handle;
  257. int setup_sorting(struct evlist *evlist);
  258. int setup_output_field(void);
  259. void reset_output_field(void);
  260. void sort__setup_elide(FILE *fp);
  261. void perf_hpp__set_elide(int idx, bool elide);
  262. char *sort_help(const char *prefix);
  263. int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
  264. bool is_strict_order(const char *order);
  265. int hpp_dimension__add_output(unsigned col);
  266. void reset_dimensions(void);
  267. int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
  268. struct evlist *evlist,
  269. int level);
  270. int output_field_add(struct perf_hpp_list *list, char *tok);
  271. int64_t
  272. sort__iaddr_cmp(struct hist_entry *left, struct hist_entry *right);
  273. int64_t
  274. sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right);
  275. int64_t
  276. sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right);
  277. int64_t
  278. _sort__sym_cmp(struct symbol *sym_l, struct symbol *sym_r);
  279. char *hist_entry__srcline(struct hist_entry *he);
  280. #endif /* __PERF_SORT_H */