1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/rbtree.h>
6 #include <linux/types.h>
9 #include "events_stats.h"
13 struct hist_entry_ops;
58 HISTC_MEM_DADDR_SYMBOL,
61 HISTC_MEM_DATA_PAGE_SIZE,
67 HISTC_MEM_IADDR_SYMBOL,
79 HISTC_LOCAL_P_STAGE_CYC,
80 HISTC_GLOBAL_P_STAGE_CYC,
85 HISTC_NR_COLS, /* Last entry */
92 struct rb_root_cached entries_in_array[2];
93 struct rb_root_cached *entries_in;
94 struct rb_root_cached entries;
95 struct rb_root_cached entries_collapsed;
97 u64 nr_non_filtered_entries;
99 u64 callchain_non_filtered_period;
100 struct thread *thread_filter;
101 const struct dso *dso_filter;
102 const char *uid_filter_str;
103 const char *symbol_filter_str;
105 struct hists_stats stats;
107 u16 col_len[HISTC_NR_COLS];
110 struct perf_hpp_list *hpp_list;
111 struct list_head hpp_formats;
115 #define hists__has(__h, __f) (__h)->hpp_list->__f
117 struct hist_entry_iter;
119 struct hist_iter_ops {
120 int (*prepare_entry)(struct hist_entry_iter *, struct addr_location *);
121 int (*add_single_entry)(struct hist_entry_iter *, struct addr_location *);
122 int (*next_entry)(struct hist_entry_iter *, struct addr_location *);
123 int (*add_next_entry)(struct hist_entry_iter *, struct addr_location *);
124 int (*finish_entry)(struct hist_entry_iter *, struct addr_location *);
127 struct hist_entry_iter {
131 bool hide_unresolved;
134 struct perf_sample *sample;
135 struct hist_entry *he;
136 struct symbol *parent;
139 const struct hist_iter_ops *ops;
140 /* user-defined callback function (optional) */
141 int (*add_entry_cb)(struct hist_entry_iter *iter,
142 struct addr_location *al, bool single, void *arg);
145 extern const struct hist_iter_ops hist_iter_normal;
146 extern const struct hist_iter_ops hist_iter_branch;
147 extern const struct hist_iter_ops hist_iter_mem;
148 extern const struct hist_iter_ops hist_iter_cumulative;
150 struct hist_entry *hists__add_entry(struct hists *hists,
151 struct addr_location *al,
152 struct symbol *parent,
153 struct branch_info *bi,
156 struct perf_sample *sample,
159 struct hist_entry *hists__add_entry_ops(struct hists *hists,
160 struct hist_entry_ops *ops,
161 struct addr_location *al,
162 struct symbol *sym_parent,
163 struct branch_info *bi,
166 struct perf_sample *sample,
169 struct hist_entry *hists__add_entry_block(struct hists *hists,
170 struct addr_location *al,
171 struct block_info *bi);
173 int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
174 int max_stack_depth, void *arg);
179 int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right);
180 int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right);
181 int hist_entry__transaction_len(void);
182 int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
183 struct hists *hists);
184 int hist_entry__snprintf_alignment(struct hist_entry *he, struct perf_hpp *hpp,
185 struct perf_hpp_fmt *fmt, int printed);
186 void hist_entry__delete(struct hist_entry *he);
188 typedef int (*hists__resort_cb_t)(struct hist_entry *he, void *arg);
190 void evsel__output_resort_cb(struct evsel *evsel, struct ui_progress *prog,
191 hists__resort_cb_t cb, void *cb_arg);
192 void evsel__output_resort(struct evsel *evsel, struct ui_progress *prog);
193 void hists__output_resort(struct hists *hists, struct ui_progress *prog);
194 void hists__output_resort_cb(struct hists *hists, struct ui_progress *prog,
195 hists__resort_cb_t cb);
196 int hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
198 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
199 void hists__delete_entries(struct hists *hists);
200 void hists__output_recalc_col_len(struct hists *hists, int max_rows);
202 struct hist_entry *hists__get_entry(struct hists *hists, int idx);
204 u64 hists__total_period(struct hists *hists);
205 void hists__reset_stats(struct hists *hists);
206 void hists__inc_stats(struct hists *hists, struct hist_entry *h);
207 void hists__inc_nr_events(struct hists *hists);
208 void hists__inc_nr_samples(struct hists *hists, bool filtered);
209 void hists__inc_nr_lost_samples(struct hists *hists, u32 lost);
211 size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
212 int max_cols, float min_pcnt, FILE *fp,
213 bool ignore_callchains);
214 size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp,
217 void hists__filter_by_dso(struct hists *hists);
218 void hists__filter_by_thread(struct hists *hists);
219 void hists__filter_by_symbol(struct hists *hists);
220 void hists__filter_by_socket(struct hists *hists);
222 static inline bool hists__has_filter(struct hists *hists)
224 return hists->thread_filter || hists->dso_filter ||
225 hists->symbol_filter_str || (hists->socket_filter > -1);
228 u16 hists__col_len(struct hists *hists, enum hist_column col);
229 void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
230 bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
231 void hists__reset_col_len(struct hists *hists);
232 void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
234 void hists__match(struct hists *leader, struct hists *other);
235 int hists__link(struct hists *leader, struct hists *other);
236 int hists__unlink(struct hists *hists);
243 static inline struct evsel *hists_to_evsel(struct hists *hists)
245 struct hists_evsel *hevsel = container_of(hists, struct hists_evsel, hists);
246 return &hevsel->evsel;
249 static inline struct hists *evsel__hists(struct evsel *evsel)
251 struct hists_evsel *hevsel = (struct hists_evsel *)evsel;
252 return &hevsel->hists;
255 static __pure inline bool hists__has_callchains(struct hists *hists)
257 return hists->has_callchains;
260 int hists__init(void);
261 int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list);
263 struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists);
273 struct perf_hpp_fmt {
275 int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
276 struct hists *hists, int line, int *span);
277 int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
278 struct hists *hists);
279 void (*init)(struct perf_hpp_fmt *fmt, struct hist_entry *he);
280 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
281 struct hist_entry *he);
282 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
283 struct hist_entry *he);
284 int64_t (*cmp)(struct perf_hpp_fmt *fmt,
285 struct hist_entry *a, struct hist_entry *b);
286 int64_t (*collapse)(struct perf_hpp_fmt *fmt,
287 struct hist_entry *a, struct hist_entry *b);
288 int64_t (*sort)(struct perf_hpp_fmt *fmt,
289 struct hist_entry *a, struct hist_entry *b);
290 bool (*equal)(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);
291 void (*free)(struct perf_hpp_fmt *fmt);
293 struct list_head list;
294 struct list_head sort_list;
302 struct perf_hpp_list {
303 struct list_head fields;
304 struct list_head sorts;
316 extern struct perf_hpp_list perf_hpp_list;
318 struct perf_hpp_list_node {
319 struct list_head list;
320 struct perf_hpp_list hpp;
325 void perf_hpp_list__column_register(struct perf_hpp_list *list,
326 struct perf_hpp_fmt *format);
327 void perf_hpp_list__register_sort_field(struct perf_hpp_list *list,
328 struct perf_hpp_fmt *format);
329 void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,
330 struct perf_hpp_fmt *format);
332 static inline void perf_hpp__column_register(struct perf_hpp_fmt *format)
334 perf_hpp_list__column_register(&perf_hpp_list, format);
337 static inline void perf_hpp__register_sort_field(struct perf_hpp_fmt *format)
339 perf_hpp_list__register_sort_field(&perf_hpp_list, format);
342 static inline void perf_hpp__prepend_sort_field(struct perf_hpp_fmt *format)
344 perf_hpp_list__prepend_sort_field(&perf_hpp_list, format);
347 #define perf_hpp_list__for_each_format(_list, format) \
348 list_for_each_entry(format, &(_list)->fields, list)
350 #define perf_hpp_list__for_each_format_safe(_list, format, tmp) \
351 list_for_each_entry_safe(format, tmp, &(_list)->fields, list)
353 #define perf_hpp_list__for_each_sort_list(_list, format) \
354 list_for_each_entry(format, &(_list)->sorts, sort_list)
356 #define perf_hpp_list__for_each_sort_list_safe(_list, format, tmp) \
357 list_for_each_entry_safe(format, tmp, &(_list)->sorts, sort_list)
359 #define hists__for_each_format(hists, format) \
360 perf_hpp_list__for_each_format((hists)->hpp_list, format)
362 #define hists__for_each_sort_list(hists, format) \
363 perf_hpp_list__for_each_sort_list((hists)->hpp_list, format)
365 extern struct perf_hpp_fmt perf_hpp__format[];
368 /* Matches perf_hpp__format array. */
370 PERF_HPP__OVERHEAD_SYS,
371 PERF_HPP__OVERHEAD_US,
372 PERF_HPP__OVERHEAD_GUEST_SYS,
373 PERF_HPP__OVERHEAD_GUEST_US,
374 PERF_HPP__OVERHEAD_ACC,
381 void perf_hpp__init(void);
382 void perf_hpp__cancel_cumulate(void);
383 void perf_hpp__setup_output_field(struct perf_hpp_list *list);
384 void perf_hpp__reset_output_field(struct perf_hpp_list *list);
385 void perf_hpp__append_sort_keys(struct perf_hpp_list *list);
386 int perf_hpp__setup_hists_formats(struct perf_hpp_list *list,
387 struct evlist *evlist);
390 bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
391 bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *format);
392 bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists);
393 bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt);
394 bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt);
395 bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt);
396 bool perf_hpp__is_thread_entry(struct perf_hpp_fmt *fmt);
397 bool perf_hpp__is_comm_entry(struct perf_hpp_fmt *fmt);
398 bool perf_hpp__is_dso_entry(struct perf_hpp_fmt *fmt);
399 bool perf_hpp__is_sym_entry(struct perf_hpp_fmt *fmt);
401 struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt);
403 int hist_entry__filter(struct hist_entry *he, int type, const void *arg);
405 static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format,
411 if (perf_hpp__is_dynamic_entry(format) &&
412 !perf_hpp__defined_dynamic_entry(format, hists))
418 void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
419 void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists);
420 void perf_hpp__set_user_width(const char *width_list_str);
421 void hists__reset_column_width(struct hists *hists);
423 typedef u64 (*hpp_field_fn)(struct hist_entry *he);
424 typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
425 typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
427 int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
428 struct hist_entry *he, hpp_field_fn get_field,
429 const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);
430 int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
431 struct hist_entry *he, hpp_field_fn get_field,
432 const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);
434 static inline void advance_hpp(struct perf_hpp *hpp, int inc)
440 static inline size_t perf_hpp__use_color(void)
442 return !symbol_conf.field_sep;
445 static inline size_t perf_hpp__color_overhead(void)
447 return perf_hpp__use_color() ?
448 (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
454 struct hist_browser_timer {
455 void (*timer)(void *arg);
460 struct annotation_options;
471 #ifdef HAVE_SLANG_SUPPORT
472 #include "../ui/keysyms.h"
473 void attr_to_script(char *buf, struct perf_event_attr *attr);
475 int map_symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
476 struct hist_browser_timer *hbt,
477 struct annotation_options *annotation_opts);
479 int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
480 struct hist_browser_timer *hbt,
481 struct annotation_options *annotation_opts);
483 int evlist__tui_browse_hists(struct evlist *evlist, const char *help, struct hist_browser_timer *hbt,
484 float min_pcnt, struct perf_env *env, bool warn_lost_event,
485 struct annotation_options *annotation_options);
487 int script_browse(const char *script_opt, struct evsel *evsel);
489 void run_script(char *cmd);
490 int res_sample_browse(struct res_sample *res_samples, int num_res,
491 struct evsel *evsel, enum rstype rstype);
492 void res_sample_init(void);
494 int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
495 float min_percent, struct perf_env *env,
496 struct annotation_options *annotation_opts);
499 int evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,
500 const char *help __maybe_unused,
501 struct hist_browser_timer *hbt __maybe_unused,
502 float min_pcnt __maybe_unused,
503 struct perf_env *env __maybe_unused,
504 bool warn_lost_event __maybe_unused,
505 struct annotation_options *annotation_options __maybe_unused)
509 static inline int map_symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
510 struct evsel *evsel __maybe_unused,
511 struct hist_browser_timer *hbt __maybe_unused,
512 struct annotation_options *annotation_options __maybe_unused)
517 static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
518 struct evsel *evsel __maybe_unused,
519 struct hist_browser_timer *hbt __maybe_unused,
520 struct annotation_options *annotation_opts __maybe_unused)
525 static inline int script_browse(const char *script_opt __maybe_unused,
526 struct evsel *evsel __maybe_unused)
531 static inline int res_sample_browse(struct res_sample *res_samples __maybe_unused,
532 int num_res __maybe_unused,
533 struct evsel *evsel __maybe_unused,
534 enum rstype rstype __maybe_unused)
539 static inline void res_sample_init(void) {}
541 static inline int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
542 struct evsel *evsel __maybe_unused,
543 float min_percent __maybe_unused,
544 struct perf_env *env __maybe_unused,
545 struct annotation_options *annotation_opts __maybe_unused)
551 #define K_RIGHT -2000
552 #define K_SWITCH_INPUT_DATA -3000
553 #define K_RELOAD -4000
556 unsigned int hists__sort_list_width(struct hists *hists);
557 unsigned int hists__overhead_width(struct hists *hists);
559 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
560 struct perf_sample *sample, bool nonany_branch_mode,
564 int parse_filter_percentage(const struct option *opt, const char *arg, int unset);
565 int perf_hist_config(const char *var, const char *value);
567 void perf_hpp_list__init(struct perf_hpp_list *list);
569 enum hierarchy_move_dir {
575 struct rb_node *rb_hierarchy_last(struct rb_node *node);
576 struct rb_node *__rb_hierarchy_next(struct rb_node *node,
577 enum hierarchy_move_dir hmd);
578 struct rb_node *rb_hierarchy_prev(struct rb_node *node);
580 static inline struct rb_node *rb_hierarchy_next(struct rb_node *node)
582 return __rb_hierarchy_next(node, HMD_NORMAL);
585 #define HIERARCHY_INDENT 3
587 bool hist_entry__has_hierarchy_children(struct hist_entry *he, float limit);
588 int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...);
589 int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...);
590 int __hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp,
591 struct perf_hpp_list *hpp_list);
592 int hists__fprintf_headers(struct hists *hists, FILE *fp);
593 int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool show_freq);
595 static inline int hists__scnprintf_title(struct hists *hists, char *bf, size_t size)
597 return __hists__scnprintf_title(hists, bf, size, true);
600 #endif /* __PERF_HIST_H */