hist.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. void hists__filter_by_dso(struct hists *hists);
  102. void hists__filter_by_thread(struct hists *hists);
  103. void hists__filter_by_symbol(struct hists *hists);
  104. u16 hists__col_len(struct hists *hists, enum hist_column col);
  105. void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
  106. bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
  107. void hists__reset_col_len(struct hists *hists);
  108. void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
  109. void hists__match(struct hists *leader, struct hists *other);
  110. int hists__link(struct hists *leader, struct hists *other);
  111. struct perf_hpp {
  112. char *buf;
  113. size_t size;
  114. const char *sep;
  115. void *ptr;
  116. };
  117. struct perf_hpp_fmt {
  118. int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp);
  119. int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp);
  120. int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  121. struct hist_entry *he);
  122. int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
  123. struct hist_entry *he);
  124. struct list_head list;
  125. };
  126. extern struct list_head perf_hpp__list;
  127. #define perf_hpp__for_each_format(format) \
  128. list_for_each_entry(format, &perf_hpp__list, list)
  129. extern struct perf_hpp_fmt perf_hpp__format[];
  130. enum {
  131. /* Matches perf_hpp__format array. */
  132. PERF_HPP__OVERHEAD,
  133. PERF_HPP__OVERHEAD_SYS,
  134. PERF_HPP__OVERHEAD_US,
  135. PERF_HPP__OVERHEAD_GUEST_SYS,
  136. PERF_HPP__OVERHEAD_GUEST_US,
  137. PERF_HPP__SAMPLES,
  138. PERF_HPP__PERIOD,
  139. PERF_HPP__MAX_INDEX
  140. };
  141. void perf_hpp__init(void);
  142. void perf_hpp__column_register(struct perf_hpp_fmt *format);
  143. void perf_hpp__column_enable(unsigned col);
  144. static inline size_t perf_hpp__use_color(void)
  145. {
  146. return !symbol_conf.field_sep;
  147. }
  148. static inline size_t perf_hpp__color_overhead(void)
  149. {
  150. return perf_hpp__use_color() ?
  151. (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
  152. : 0;
  153. }
  154. struct perf_evlist;
  155. struct hist_browser_timer {
  156. void (*timer)(void *arg);
  157. void *arg;
  158. int refresh;
  159. };
  160. #ifdef HAVE_SLANG_SUPPORT
  161. #include "../ui/keysyms.h"
  162. int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
  163. struct hist_browser_timer *hbt);
  164. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
  165. struct hist_browser_timer *hbt,
  166. float min_pcnt,
  167. struct perf_session_env *env);
  168. int script_browse(const char *script_opt);
  169. #else
  170. static inline
  171. int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
  172. const char *help __maybe_unused,
  173. struct hist_browser_timer *hbt __maybe_unused,
  174. float min_pcnt __maybe_unused,
  175. struct perf_session_env *env __maybe_unused)
  176. {
  177. return 0;
  178. }
  179. static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
  180. struct perf_evsel *evsel __maybe_unused,
  181. struct hist_browser_timer *hbt __maybe_unused)
  182. {
  183. return 0;
  184. }
  185. static inline int script_browse(const char *script_opt __maybe_unused)
  186. {
  187. return 0;
  188. }
  189. #define K_LEFT -1000
  190. #define K_RIGHT -2000
  191. #define K_SWITCH_INPUT_DATA -3000
  192. #endif
  193. unsigned int hists__sort_list_width(struct hists *hists);
  194. #endif /* __PERF_HIST_H */