hist.h 6.5 KB

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