hist.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 "header.h"
  7. #include "color.h"
  8. #include "ui/progress.h"
  9. extern struct callchain_param callchain_param;
  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. };
  21. /*
  22. * The kernel collects the number of events it couldn't send in a stretch and
  23. * when possible sends this number in a PERF_RECORD_LOST event. The number of
  24. * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
  25. * total_lost tells exactly how many events the kernel in fact lost, i.e. it is
  26. * the sum of all struct lost_event.lost fields reported.
  27. *
  28. * The total_period is needed because by default auto-freq is used, so
  29. * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get
  30. * the total number of low level events, it is necessary to to sum all struct
  31. * sample_event.period and stash the result in total_period.
  32. */
  33. struct events_stats {
  34. u64 total_period;
  35. u64 total_non_filtered_period;
  36. u64 total_lost;
  37. u64 total_invalid_chains;
  38. u32 nr_events[PERF_RECORD_HEADER_MAX];
  39. u32 nr_non_filtered_samples;
  40. u32 nr_lost_warned;
  41. u32 nr_unknown_events;
  42. u32 nr_invalid_chains;
  43. u32 nr_unknown_id;
  44. u32 nr_unprocessable_samples;
  45. };
  46. enum hist_column {
  47. HISTC_SYMBOL,
  48. HISTC_DSO,
  49. HISTC_THREAD,
  50. HISTC_COMM,
  51. HISTC_PARENT,
  52. HISTC_CPU,
  53. HISTC_SRCLINE,
  54. HISTC_MISPREDICT,
  55. HISTC_IN_TX,
  56. HISTC_ABORT,
  57. HISTC_SYMBOL_FROM,
  58. HISTC_SYMBOL_TO,
  59. HISTC_DSO_FROM,
  60. HISTC_DSO_TO,
  61. HISTC_LOCAL_WEIGHT,
  62. HISTC_GLOBAL_WEIGHT,
  63. HISTC_MEM_DADDR_SYMBOL,
  64. HISTC_MEM_DADDR_DSO,
  65. HISTC_MEM_LOCKED,
  66. HISTC_MEM_TLB,
  67. HISTC_MEM_LVL,
  68. HISTC_MEM_SNOOP,
  69. HISTC_TRANSACTION,
  70. HISTC_NR_COLS, /* Last entry */
  71. };
  72. struct thread;
  73. struct dso;
  74. struct hists {
  75. struct rb_root entries_in_array[2];
  76. struct rb_root *entries_in;
  77. struct rb_root entries;
  78. struct rb_root entries_collapsed;
  79. u64 nr_entries;
  80. u64 nr_non_filtered_entries;
  81. const struct thread *thread_filter;
  82. const struct dso *dso_filter;
  83. const char *uid_filter_str;
  84. const char *symbol_filter_str;
  85. pthread_mutex_t lock;
  86. struct events_stats stats;
  87. u64 event_stream;
  88. u16 col_len[HISTC_NR_COLS];
  89. };
  90. struct hist_entry *__hists__add_entry(struct hists *hists,
  91. struct addr_location *al,
  92. struct symbol *parent,
  93. struct branch_info *bi,
  94. struct mem_info *mi, u64 period,
  95. u64 weight, u64 transaction);
  96. int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right);
  97. int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right);
  98. int hist_entry__transaction_len(void);
  99. int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
  100. struct hists *hists);
  101. void hist_entry__free(struct hist_entry *);
  102. void hists__output_resort(struct hists *hists);
  103. void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
  104. void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
  105. void hists__output_recalc_col_len(struct hists *hists, int max_rows);
  106. u64 hists__total_period(struct hists *hists);
  107. void hists__reset_stats(struct hists *hists);
  108. void hists__inc_stats(struct hists *hists, struct hist_entry *h);
  109. void hists__inc_nr_events(struct hists *hists, u32 type);
  110. void events_stats__inc(struct events_stats *stats, u32 type);
  111. size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);
  112. size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
  113. int max_cols, float min_pcnt, FILE *fp);
  114. void hists__filter_by_dso(struct hists *hists);
  115. void hists__filter_by_thread(struct hists *hists);
  116. void hists__filter_by_symbol(struct hists *hists);
  117. static inline bool hists__has_filter(struct hists *hists)
  118. {
  119. return hists->thread_filter || hists->dso_filter ||
  120. hists->symbol_filter_str;
  121. }
  122. u16 hists__col_len(struct hists *hists, enum hist_column col);
  123. void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
  124. bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
  125. void hists__reset_col_len(struct hists *hists);
  126. void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
  127. void hists__match(struct hists *leader, struct hists *other);
  128. int hists__link(struct hists *leader, struct hists *other);
  129. struct perf_hpp {
  130. char *buf;
  131. size_t size;
  132. const char *sep;
  133. void *ptr;
  134. };
  135. struct perf_hpp_fmt {
  136. int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  137. struct perf_evsel *evsel);
  138. int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  139. struct perf_evsel *evsel);
  140. int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  141. struct hist_entry *he);
  142. int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  143. struct hist_entry *he);
  144. int64_t (*cmp)(struct hist_entry *a, struct hist_entry *b);
  145. int64_t (*collapse)(struct hist_entry *a, struct hist_entry *b);
  146. int64_t (*sort)(struct hist_entry *a, struct hist_entry *b);
  147. struct list_head list;
  148. struct list_head sort_list;
  149. };
  150. extern struct list_head perf_hpp__list;
  151. extern struct list_head perf_hpp__sort_list;
  152. #define perf_hpp__for_each_format(format) \
  153. list_for_each_entry(format, &perf_hpp__list, list)
  154. #define perf_hpp__for_each_sort_list(format) \
  155. list_for_each_entry(format, &perf_hpp__sort_list, sort_list)
  156. extern struct perf_hpp_fmt perf_hpp__format[];
  157. enum {
  158. /* Matches perf_hpp__format array. */
  159. PERF_HPP__OVERHEAD,
  160. PERF_HPP__OVERHEAD_SYS,
  161. PERF_HPP__OVERHEAD_US,
  162. PERF_HPP__OVERHEAD_GUEST_SYS,
  163. PERF_HPP__OVERHEAD_GUEST_US,
  164. PERF_HPP__SAMPLES,
  165. PERF_HPP__PERIOD,
  166. PERF_HPP__MAX_INDEX
  167. };
  168. void perf_hpp__init(void);
  169. void perf_hpp__column_register(struct perf_hpp_fmt *format);
  170. void perf_hpp__column_enable(unsigned col);
  171. void perf_hpp__register_sort_field(struct perf_hpp_fmt *format);
  172. void perf_hpp__setup_output_field(void);
  173. void perf_hpp__append_sort_keys(void);
  174. bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
  175. bool perf_hpp__same_sort_entry(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);
  176. bool perf_hpp__should_skip(struct perf_hpp_fmt *format);
  177. void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
  178. typedef u64 (*hpp_field_fn)(struct hist_entry *he);
  179. typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
  180. typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
  181. int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
  182. hpp_field_fn get_field, const char *fmt,
  183. hpp_snprint_fn print_fn, bool fmt_percent);
  184. static inline void advance_hpp(struct perf_hpp *hpp, int inc)
  185. {
  186. hpp->buf += inc;
  187. hpp->size -= inc;
  188. }
  189. static inline size_t perf_hpp__use_color(void)
  190. {
  191. return !symbol_conf.field_sep;
  192. }
  193. static inline size_t perf_hpp__color_overhead(void)
  194. {
  195. return perf_hpp__use_color() ?
  196. (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
  197. : 0;
  198. }
  199. struct perf_evlist;
  200. struct hist_browser_timer {
  201. void (*timer)(void *arg);
  202. void *arg;
  203. int refresh;
  204. };
  205. #ifdef HAVE_SLANG_SUPPORT
  206. #include "../ui/keysyms.h"
  207. int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
  208. struct hist_browser_timer *hbt);
  209. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
  210. struct hist_browser_timer *hbt,
  211. float min_pcnt,
  212. struct perf_session_env *env);
  213. int script_browse(const char *script_opt);
  214. #else
  215. static inline
  216. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
  217. const char *help __maybe_unused,
  218. struct hist_browser_timer *hbt __maybe_unused,
  219. float min_pcnt __maybe_unused,
  220. struct perf_session_env *env __maybe_unused)
  221. {
  222. return 0;
  223. }
  224. static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
  225. struct perf_evsel *evsel __maybe_unused,
  226. struct hist_browser_timer *hbt __maybe_unused)
  227. {
  228. return 0;
  229. }
  230. static inline int script_browse(const char *script_opt __maybe_unused)
  231. {
  232. return 0;
  233. }
  234. #define K_LEFT -1000
  235. #define K_RIGHT -2000
  236. #define K_SWITCH_INPUT_DATA -3000
  237. #endif
  238. unsigned int hists__sort_list_width(struct hists *hists);
  239. struct option;
  240. int parse_filter_percentage(const struct option *opt __maybe_unused,
  241. const char *arg, int unset __maybe_unused);
  242. int perf_hist_config(const char *var, const char *value);
  243. #endif /* __PERF_HIST_H */