hist.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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_lost;
  36. u64 total_invalid_chains;
  37. u32 nr_events[PERF_RECORD_HEADER_MAX];
  38. u32 nr_lost_warned;
  39. u32 nr_unknown_events;
  40. u32 nr_invalid_chains;
  41. u32 nr_unknown_id;
  42. u32 nr_unprocessable_samples;
  43. };
  44. enum hist_column {
  45. HISTC_SYMBOL,
  46. HISTC_DSO,
  47. HISTC_THREAD,
  48. HISTC_COMM,
  49. HISTC_PARENT,
  50. HISTC_CPU,
  51. HISTC_SRCLINE,
  52. HISTC_MISPREDICT,
  53. HISTC_IN_TX,
  54. HISTC_ABORT,
  55. HISTC_SYMBOL_FROM,
  56. HISTC_SYMBOL_TO,
  57. HISTC_DSO_FROM,
  58. HISTC_DSO_TO,
  59. HISTC_LOCAL_WEIGHT,
  60. HISTC_GLOBAL_WEIGHT,
  61. HISTC_MEM_DADDR_SYMBOL,
  62. HISTC_MEM_DADDR_DSO,
  63. HISTC_MEM_LOCKED,
  64. HISTC_MEM_TLB,
  65. HISTC_MEM_LVL,
  66. HISTC_MEM_SNOOP,
  67. HISTC_TRANSACTION,
  68. HISTC_NR_COLS, /* Last entry */
  69. };
  70. struct thread;
  71. struct dso;
  72. struct hists {
  73. struct rb_root entries_in_array[2];
  74. struct rb_root *entries_in;
  75. struct rb_root entries;
  76. struct rb_root entries_collapsed;
  77. u64 nr_entries;
  78. const struct thread *thread_filter;
  79. const struct dso *dso_filter;
  80. const char *uid_filter_str;
  81. const char *symbol_filter_str;
  82. pthread_mutex_t lock;
  83. struct events_stats stats;
  84. u64 event_stream;
  85. u16 col_len[HISTC_NR_COLS];
  86. };
  87. struct hist_entry *__hists__add_entry(struct hists *hists,
  88. struct addr_location *al,
  89. struct symbol *parent,
  90. struct branch_info *bi,
  91. struct mem_info *mi, u64 period,
  92. u64 weight, u64 transaction);
  93. int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right);
  94. int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right);
  95. int hist_entry__transaction_len(void);
  96. int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
  97. struct hists *hists);
  98. void hist_entry__free(struct hist_entry *);
  99. void hists__output_resort(struct hists *hists);
  100. void hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
  101. void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
  102. void hists__output_recalc_col_len(struct hists *hists, int max_rows);
  103. void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h);
  104. void hists__inc_nr_events(struct hists *hists, u32 type);
  105. void events_stats__inc(struct events_stats *stats, u32 type);
  106. size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);
  107. size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
  108. int max_cols, float min_pcnt, FILE *fp);
  109. void hists__filter_by_dso(struct hists *hists);
  110. void hists__filter_by_thread(struct hists *hists);
  111. void hists__filter_by_symbol(struct hists *hists);
  112. u16 hists__col_len(struct hists *hists, enum hist_column col);
  113. void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
  114. bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
  115. void hists__reset_col_len(struct hists *hists);
  116. void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
  117. void hists__match(struct hists *leader, struct hists *other);
  118. int hists__link(struct hists *leader, struct hists *other);
  119. struct perf_hpp {
  120. char *buf;
  121. size_t size;
  122. const char *sep;
  123. void *ptr;
  124. };
  125. struct perf_hpp_fmt {
  126. int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  127. struct perf_evsel *evsel);
  128. int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  129. struct perf_evsel *evsel);
  130. int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  131. struct hist_entry *he);
  132. int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  133. struct hist_entry *he);
  134. struct list_head list;
  135. };
  136. extern struct list_head perf_hpp__list;
  137. #define perf_hpp__for_each_format(format) \
  138. list_for_each_entry(format, &perf_hpp__list, list)
  139. extern struct perf_hpp_fmt perf_hpp__format[];
  140. enum {
  141. /* Matches perf_hpp__format array. */
  142. PERF_HPP__OVERHEAD,
  143. PERF_HPP__OVERHEAD_SYS,
  144. PERF_HPP__OVERHEAD_US,
  145. PERF_HPP__OVERHEAD_GUEST_SYS,
  146. PERF_HPP__OVERHEAD_GUEST_US,
  147. PERF_HPP__SAMPLES,
  148. PERF_HPP__PERIOD,
  149. PERF_HPP__MAX_INDEX
  150. };
  151. void perf_hpp__init(void);
  152. void perf_hpp__column_register(struct perf_hpp_fmt *format);
  153. void perf_hpp__column_enable(unsigned col);
  154. typedef u64 (*hpp_field_fn)(struct hist_entry *he);
  155. typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
  156. typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
  157. int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
  158. hpp_field_fn get_field, hpp_callback_fn callback,
  159. const char *fmt, hpp_snprint_fn print_fn, bool fmt_percent);
  160. static inline void advance_hpp(struct perf_hpp *hpp, int inc)
  161. {
  162. hpp->buf += inc;
  163. hpp->size -= inc;
  164. }
  165. static inline size_t perf_hpp__use_color(void)
  166. {
  167. return !symbol_conf.field_sep;
  168. }
  169. static inline size_t perf_hpp__color_overhead(void)
  170. {
  171. return perf_hpp__use_color() ?
  172. (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
  173. : 0;
  174. }
  175. struct perf_evlist;
  176. struct hist_browser_timer {
  177. void (*timer)(void *arg);
  178. void *arg;
  179. int refresh;
  180. };
  181. #ifdef HAVE_SLANG_SUPPORT
  182. #include "../ui/keysyms.h"
  183. int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
  184. struct hist_browser_timer *hbt);
  185. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
  186. struct hist_browser_timer *hbt,
  187. float min_pcnt,
  188. struct perf_session_env *env);
  189. int script_browse(const char *script_opt);
  190. #else
  191. static inline
  192. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
  193. const char *help __maybe_unused,
  194. struct hist_browser_timer *hbt __maybe_unused,
  195. float min_pcnt __maybe_unused,
  196. struct perf_session_env *env __maybe_unused)
  197. {
  198. return 0;
  199. }
  200. static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
  201. struct perf_evsel *evsel __maybe_unused,
  202. struct hist_browser_timer *hbt __maybe_unused)
  203. {
  204. return 0;
  205. }
  206. static inline int script_browse(const char *script_opt __maybe_unused)
  207. {
  208. return 0;
  209. }
  210. #define K_LEFT -1000
  211. #define K_RIGHT -2000
  212. #define K_SWITCH_INPUT_DATA -3000
  213. #endif
  214. unsigned int hists__sort_list_width(struct hists *hists);
  215. #endif /* __PERF_HIST_H */