hist.h 7.1 KB

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