hist.h 6.5 KB

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