PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/perf/util/sort.h

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