hist.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #ifndef __PERF_HIST_H
  2. #define __PERF_HIST_H
  3. #include <linux/types.h>
  4. #include <pthread.h>
  5. #include "callchain.h"
  6. #include "evsel.h"
  7. #include "header.h"
  8. #include "color.h"
  9. #include "ui/progress.h"
  10. struct hist_entry;
  11. struct addr_location;
  12. struct symbol;
  13. enum hist_filter {
  14. HIST_FILTER__DSO,
  15. HIST_FILTER__THREAD,
  16. HIST_FILTER__PARENT,
  17. HIST_FILTER__SYMBOL,
  18. HIST_FILTER__GUEST,
  19. HIST_FILTER__HOST,
  20. HIST_FILTER__SOCKET,
  21. };
  22. enum hist_column {
  23. HISTC_SYMBOL,
  24. HISTC_DSO,
  25. HISTC_THREAD,
  26. HISTC_COMM,
  27. HISTC_PARENT,
  28. HISTC_CPU,
  29. HISTC_SOCKET,
  30. HISTC_SRCLINE,
  31. HISTC_SRCFILE,
  32. HISTC_MISPREDICT,
  33. HISTC_IN_TX,
  34. HISTC_ABORT,
  35. HISTC_SYMBOL_FROM,
  36. HISTC_SYMBOL_TO,
  37. HISTC_DSO_FROM,
  38. HISTC_DSO_TO,
  39. HISTC_LOCAL_WEIGHT,
  40. HISTC_GLOBAL_WEIGHT,
  41. HISTC_MEM_DADDR_SYMBOL,
  42. HISTC_MEM_DADDR_DSO,
  43. HISTC_MEM_LOCKED,
  44. HISTC_MEM_TLB,
  45. HISTC_MEM_LVL,
  46. HISTC_MEM_SNOOP,
  47. HISTC_MEM_DCACHELINE,
  48. HISTC_MEM_IADDR_SYMBOL,
  49. HISTC_TRANSACTION,
  50. HISTC_CYCLES,
  51. HISTC_NR_COLS, /* Last entry */
  52. };
  53. struct thread;
  54. struct dso;
  55. struct hists {
  56. struct rb_root entries_in_array[2];
  57. struct rb_root *entries_in;
  58. struct rb_root entries;
  59. struct rb_root entries_collapsed;
  60. u64 nr_entries;
  61. u64 nr_non_filtered_entries;
  62. struct thread *thread_filter;
  63. const struct dso *dso_filter;
  64. const char *uid_filter_str;
  65. const char *symbol_filter_str;
  66. pthread_mutex_t lock;
  67. struct events_stats stats;
  68. u64 event_stream;
  69. u16 col_len[HISTC_NR_COLS];
  70. int socket_filter;
  71. };
  72. struct hist_entry_iter;
  73. struct hist_iter_ops {
  74. int (*prepare_entry)(struct hist_entry_iter *, struct addr_location *);
  75. int (*add_single_entry)(struct hist_entry_iter *, struct addr_location *);
  76. int (*next_entry)(struct hist_entry_iter *, struct addr_location *);
  77. int (*add_next_entry)(struct hist_entry_iter *, struct addr_location *);
  78. int (*finish_entry)(struct hist_entry_iter *, struct addr_location *);
  79. };
  80. struct hist_entry_iter {
  81. int total;
  82. int curr;
  83. bool hide_unresolved;
  84. int max_stack;
  85. struct perf_evsel *evsel;
  86. struct perf_sample *sample;
  87. struct hist_entry *he;
  88. struct symbol *parent;
  89. void *priv;
  90. const struct hist_iter_ops *ops;
  91. /* user-defined callback function (optional) */
  92. int (*add_entry_cb)(struct hist_entry_iter *iter,
  93. struct addr_location *al, bool single, void *arg);
  94. };
  95. extern const struct hist_iter_ops hist_iter_normal;
  96. extern const struct hist_iter_ops hist_iter_branch;
  97. extern const struct hist_iter_ops hist_iter_mem;
  98. extern const struct hist_iter_ops hist_iter_cumulative;
  99. struct hist_entry *__hists__add_entry(struct hists *hists,
  100. struct addr_location *al,
  101. struct symbol *parent,
  102. struct branch_info *bi,
  103. struct mem_info *mi, u64 period,
  104. u64 weight, u64 transaction,
  105. bool sample_self);
  106. int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
  107. int max_stack_depth, void *arg);
  108. int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right);
  109. int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right);
  110. int hist_entry__transaction_len(void);
  111. int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
  112. struct hists *hists);
  113. void hist_entry__delete(struct hist_entry *he);
  114. void hists__output_resort(struct hists *hists, struct ui_progress *prog);
  115. void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
  116. void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
  117. void hists__delete_entries(struct hists *hists);
  118. void hists__output_recalc_col_len(struct hists *hists, int max_rows);
  119. u64 hists__total_period(struct hists *hists);
  120. void hists__reset_stats(struct hists *hists);
  121. void hists__inc_stats(struct hists *hists, struct hist_entry *h);
  122. void hists__inc_nr_events(struct hists *hists, u32 type);
  123. void hists__inc_nr_samples(struct hists *hists, bool filtered);
  124. void events_stats__inc(struct events_stats *stats, u32 type);
  125. size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);
  126. size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
  127. int max_cols, float min_pcnt, FILE *fp);
  128. size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp);
  129. void hists__filter_by_dso(struct hists *hists);
  130. void hists__filter_by_thread(struct hists *hists);
  131. void hists__filter_by_symbol(struct hists *hists);
  132. void hists__filter_by_socket(struct hists *hists);
  133. static inline bool hists__has_filter(struct hists *hists)
  134. {
  135. return hists->thread_filter || hists->dso_filter ||
  136. hists->symbol_filter_str || (hists->socket_filter > -1);
  137. }
  138. u16 hists__col_len(struct hists *hists, enum hist_column col);
  139. void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
  140. bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
  141. void hists__reset_col_len(struct hists *hists);
  142. void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
  143. void hists__match(struct hists *leader, struct hists *other);
  144. int hists__link(struct hists *leader, struct hists *other);
  145. struct hists_evsel {
  146. struct perf_evsel evsel;
  147. struct hists hists;
  148. };
  149. static inline struct perf_evsel *hists_to_evsel(struct hists *hists)
  150. {
  151. struct hists_evsel *hevsel = container_of(hists, struct hists_evsel, hists);
  152. return &hevsel->evsel;
  153. }
  154. static inline struct hists *evsel__hists(struct perf_evsel *evsel)
  155. {
  156. struct hists_evsel *hevsel = (struct hists_evsel *)evsel;
  157. return &hevsel->hists;
  158. }
  159. int hists__init(void);
  160. struct perf_hpp {
  161. char *buf;
  162. size_t size;
  163. const char *sep;
  164. void *ptr;
  165. };
  166. struct perf_hpp_fmt {
  167. const char *name;
  168. int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  169. struct perf_evsel *evsel);
  170. int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  171. struct perf_evsel *evsel);
  172. int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  173. struct hist_entry *he);
  174. int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  175. struct hist_entry *he);
  176. int64_t (*cmp)(struct perf_hpp_fmt *fmt,
  177. struct hist_entry *a, struct hist_entry *b);
  178. int64_t (*collapse)(struct perf_hpp_fmt *fmt,
  179. struct hist_entry *a, struct hist_entry *b);
  180. int64_t (*sort)(struct perf_hpp_fmt *fmt,
  181. struct hist_entry *a, struct hist_entry *b);
  182. struct list_head list;
  183. struct list_head sort_list;
  184. bool elide;
  185. int len;
  186. int user_len;
  187. };
  188. extern struct list_head perf_hpp__list;
  189. extern struct list_head perf_hpp__sort_list;
  190. #define perf_hpp__for_each_format(format) \
  191. list_for_each_entry(format, &perf_hpp__list, list)
  192. #define perf_hpp__for_each_format_safe(format, tmp) \
  193. list_for_each_entry_safe(format, tmp, &perf_hpp__list, list)
  194. #define perf_hpp__for_each_sort_list(format) \
  195. list_for_each_entry(format, &perf_hpp__sort_list, sort_list)
  196. #define perf_hpp__for_each_sort_list_safe(format, tmp) \
  197. list_for_each_entry_safe(format, tmp, &perf_hpp__sort_list, sort_list)
  198. extern struct perf_hpp_fmt perf_hpp__format[];
  199. enum {
  200. /* Matches perf_hpp__format array. */
  201. PERF_HPP__OVERHEAD,
  202. PERF_HPP__OVERHEAD_SYS,
  203. PERF_HPP__OVERHEAD_US,
  204. PERF_HPP__OVERHEAD_GUEST_SYS,
  205. PERF_HPP__OVERHEAD_GUEST_US,
  206. PERF_HPP__OVERHEAD_ACC,
  207. PERF_HPP__SAMPLES,
  208. PERF_HPP__PERIOD,
  209. PERF_HPP__MAX_INDEX
  210. };
  211. void perf_hpp__init(void);
  212. void perf_hpp__column_register(struct perf_hpp_fmt *format);
  213. void perf_hpp__column_unregister(struct perf_hpp_fmt *format);
  214. void perf_hpp__column_enable(unsigned col);
  215. void perf_hpp__column_disable(unsigned col);
  216. void perf_hpp__cancel_cumulate(void);
  217. void perf_hpp__register_sort_field(struct perf_hpp_fmt *format);
  218. void perf_hpp__setup_output_field(void);
  219. void perf_hpp__reset_output_field(void);
  220. void perf_hpp__append_sort_keys(void);
  221. bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
  222. bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);
  223. static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format)
  224. {
  225. return format->elide;
  226. }
  227. void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
  228. void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists);
  229. void perf_hpp__set_user_width(const char *width_list_str);
  230. typedef u64 (*hpp_field_fn)(struct hist_entry *he);
  231. typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
  232. typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
  233. int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  234. struct hist_entry *he, hpp_field_fn get_field,
  235. const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);
  236. int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  237. struct hist_entry *he, hpp_field_fn get_field,
  238. const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);
  239. static inline void advance_hpp(struct perf_hpp *hpp, int inc)
  240. {
  241. hpp->buf += inc;
  242. hpp->size -= inc;
  243. }
  244. static inline size_t perf_hpp__use_color(void)
  245. {
  246. return !symbol_conf.field_sep;
  247. }
  248. static inline size_t perf_hpp__color_overhead(void)
  249. {
  250. return perf_hpp__use_color() ?
  251. (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
  252. : 0;
  253. }
  254. struct perf_evlist;
  255. struct hist_browser_timer {
  256. void (*timer)(void *arg);
  257. void *arg;
  258. int refresh;
  259. };
  260. #ifdef HAVE_SLANG_SUPPORT
  261. #include "../ui/keysyms.h"
  262. int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel,
  263. struct hist_browser_timer *hbt);
  264. int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
  265. struct hist_browser_timer *hbt);
  266. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
  267. struct hist_browser_timer *hbt,
  268. float min_pcnt,
  269. struct perf_env *env);
  270. int script_browse(const char *script_opt);
  271. #else
  272. static inline
  273. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
  274. const char *help __maybe_unused,
  275. struct hist_browser_timer *hbt __maybe_unused,
  276. float min_pcnt __maybe_unused,
  277. struct perf_env *env __maybe_unused)
  278. {
  279. return 0;
  280. }
  281. static inline int map_symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
  282. struct perf_evsel *evsel __maybe_unused,
  283. struct hist_browser_timer *hbt __maybe_unused)
  284. {
  285. return 0;
  286. }
  287. static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
  288. struct perf_evsel *evsel __maybe_unused,
  289. struct hist_browser_timer *hbt __maybe_unused)
  290. {
  291. return 0;
  292. }
  293. static inline int script_browse(const char *script_opt __maybe_unused)
  294. {
  295. return 0;
  296. }
  297. #define K_LEFT -1000
  298. #define K_RIGHT -2000
  299. #define K_SWITCH_INPUT_DATA -3000
  300. #endif
  301. unsigned int hists__sort_list_width(struct hists *hists);
  302. void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
  303. struct perf_sample *sample, bool nonany_branch_mode);
  304. struct option;
  305. int parse_filter_percentage(const struct option *opt __maybe_unused,
  306. const char *arg, int unset __maybe_unused);
  307. int perf_hist_config(const char *var, const char *value);
  308. #endif /* __PERF_HIST_H */