PageRenderTime 33ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/perf/util/sort.h

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