Linux 5.1.15
[linux/fpc-iii.git] / tools / perf / util / hist.h
blob76ff6c6d03b82f334ea8aa3528d8d817f164a066
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_HIST_H
3 #define __PERF_HIST_H
5 #include <linux/rbtree.h>
6 #include <linux/types.h>
7 #include <pthread.h>
8 #include "evsel.h"
9 #include "header.h"
10 #include "color.h"
11 #include "ui/progress.h"
13 struct hist_entry;
14 struct hist_entry_ops;
15 struct addr_location;
16 struct map_symbol;
17 struct mem_info;
18 struct branch_info;
19 struct symbol;
21 enum hist_filter {
22 HIST_FILTER__DSO,
23 HIST_FILTER__THREAD,
24 HIST_FILTER__PARENT,
25 HIST_FILTER__SYMBOL,
26 HIST_FILTER__GUEST,
27 HIST_FILTER__HOST,
28 HIST_FILTER__SOCKET,
29 HIST_FILTER__C2C,
32 enum hist_column {
33 HISTC_SYMBOL,
34 HISTC_TIME,
35 HISTC_DSO,
36 HISTC_THREAD,
37 HISTC_COMM,
38 HISTC_CGROUP_ID,
39 HISTC_PARENT,
40 HISTC_CPU,
41 HISTC_SOCKET,
42 HISTC_SRCLINE,
43 HISTC_SRCFILE,
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_PHYS_DADDR,
56 HISTC_MEM_LOCKED,
57 HISTC_MEM_TLB,
58 HISTC_MEM_LVL,
59 HISTC_MEM_SNOOP,
60 HISTC_MEM_DCACHELINE,
61 HISTC_MEM_IADDR_SYMBOL,
62 HISTC_TRANSACTION,
63 HISTC_CYCLES,
64 HISTC_SRCLINE_FROM,
65 HISTC_SRCLINE_TO,
66 HISTC_TRACE,
67 HISTC_SYM_SIZE,
68 HISTC_DSO_SIZE,
69 HISTC_SYMBOL_IPC,
70 HISTC_NR_COLS, /* Last entry */
73 struct thread;
74 struct dso;
76 struct hists {
77 struct rb_root_cached entries_in_array[2];
78 struct rb_root_cached *entries_in;
79 struct rb_root_cached entries;
80 struct rb_root_cached entries_collapsed;
81 u64 nr_entries;
82 u64 nr_non_filtered_entries;
83 u64 callchain_period;
84 u64 callchain_non_filtered_period;
85 struct thread *thread_filter;
86 const struct dso *dso_filter;
87 const char *uid_filter_str;
88 const char *symbol_filter_str;
89 pthread_mutex_t lock;
90 struct events_stats stats;
91 u64 event_stream;
92 u16 col_len[HISTC_NR_COLS];
93 bool has_callchains;
94 int socket_filter;
95 struct perf_hpp_list *hpp_list;
96 struct list_head hpp_formats;
97 int nr_hpp_node;
100 #define hists__has(__h, __f) (__h)->hpp_list->__f
102 struct hist_entry_iter;
104 struct hist_iter_ops {
105 int (*prepare_entry)(struct hist_entry_iter *, struct addr_location *);
106 int (*add_single_entry)(struct hist_entry_iter *, struct addr_location *);
107 int (*next_entry)(struct hist_entry_iter *, struct addr_location *);
108 int (*add_next_entry)(struct hist_entry_iter *, struct addr_location *);
109 int (*finish_entry)(struct hist_entry_iter *, struct addr_location *);
112 struct hist_entry_iter {
113 int total;
114 int curr;
116 bool hide_unresolved;
118 struct perf_evsel *evsel;
119 struct perf_sample *sample;
120 struct hist_entry *he;
121 struct symbol *parent;
122 void *priv;
124 const struct hist_iter_ops *ops;
125 /* user-defined callback function (optional) */
126 int (*add_entry_cb)(struct hist_entry_iter *iter,
127 struct addr_location *al, bool single, void *arg);
130 extern const struct hist_iter_ops hist_iter_normal;
131 extern const struct hist_iter_ops hist_iter_branch;
132 extern const struct hist_iter_ops hist_iter_mem;
133 extern const struct hist_iter_ops hist_iter_cumulative;
135 struct hist_entry *hists__add_entry(struct hists *hists,
136 struct addr_location *al,
137 struct symbol *parent,
138 struct branch_info *bi,
139 struct mem_info *mi,
140 struct perf_sample *sample,
141 bool sample_self);
143 struct hist_entry *hists__add_entry_ops(struct hists *hists,
144 struct hist_entry_ops *ops,
145 struct addr_location *al,
146 struct symbol *sym_parent,
147 struct branch_info *bi,
148 struct mem_info *mi,
149 struct perf_sample *sample,
150 bool sample_self);
152 int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
153 int max_stack_depth, void *arg);
155 struct perf_hpp;
156 struct perf_hpp_fmt;
158 int64_t hist_entry__cmp(struct hist_entry *left, struct hist_entry *right);
159 int64_t hist_entry__collapse(struct hist_entry *left, struct hist_entry *right);
160 int hist_entry__transaction_len(void);
161 int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
162 struct hists *hists);
163 int hist_entry__snprintf_alignment(struct hist_entry *he, struct perf_hpp *hpp,
164 struct perf_hpp_fmt *fmt, int printed);
165 void hist_entry__delete(struct hist_entry *he);
167 typedef int (*hists__resort_cb_t)(struct hist_entry *he, void *arg);
169 void perf_evsel__output_resort_cb(struct perf_evsel *evsel, struct ui_progress *prog,
170 hists__resort_cb_t cb, void *cb_arg);
171 void perf_evsel__output_resort(struct perf_evsel *evsel, struct ui_progress *prog);
172 void hists__output_resort(struct hists *hists, struct ui_progress *prog);
173 void hists__output_resort_cb(struct hists *hists, struct ui_progress *prog,
174 hists__resort_cb_t cb);
175 int hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
177 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
178 void hists__delete_entries(struct hists *hists);
179 void hists__output_recalc_col_len(struct hists *hists, int max_rows);
181 u64 hists__total_period(struct hists *hists);
182 void hists__reset_stats(struct hists *hists);
183 void hists__inc_stats(struct hists *hists, struct hist_entry *h);
184 void hists__inc_nr_events(struct hists *hists, u32 type);
185 void hists__inc_nr_samples(struct hists *hists, bool filtered);
186 void events_stats__inc(struct events_stats *stats, u32 type);
187 size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);
189 size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
190 int max_cols, float min_pcnt, FILE *fp,
191 bool ignore_callchains);
192 size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp);
194 void hists__filter_by_dso(struct hists *hists);
195 void hists__filter_by_thread(struct hists *hists);
196 void hists__filter_by_symbol(struct hists *hists);
197 void hists__filter_by_socket(struct hists *hists);
199 static inline bool hists__has_filter(struct hists *hists)
201 return hists->thread_filter || hists->dso_filter ||
202 hists->symbol_filter_str || (hists->socket_filter > -1);
205 u16 hists__col_len(struct hists *hists, enum hist_column col);
206 void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
207 bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
208 void hists__reset_col_len(struct hists *hists);
209 void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
211 void hists__match(struct hists *leader, struct hists *other);
212 int hists__link(struct hists *leader, struct hists *other);
214 struct hists_evsel {
215 struct perf_evsel evsel;
216 struct hists hists;
219 static inline struct perf_evsel *hists_to_evsel(struct hists *hists)
221 struct hists_evsel *hevsel = container_of(hists, struct hists_evsel, hists);
222 return &hevsel->evsel;
225 static inline struct hists *evsel__hists(struct perf_evsel *evsel)
227 struct hists_evsel *hevsel = (struct hists_evsel *)evsel;
228 return &hevsel->hists;
231 static __pure inline bool hists__has_callchains(struct hists *hists)
233 return hists->has_callchains;
236 int hists__init(void);
237 int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list);
239 struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists);
241 struct perf_hpp {
242 char *buf;
243 size_t size;
244 const char *sep;
245 void *ptr;
248 struct perf_hpp_fmt {
249 const char *name;
250 int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
251 struct hists *hists, int line, int *span);
252 int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
253 struct hists *hists);
254 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
255 struct hist_entry *he);
256 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
257 struct hist_entry *he);
258 int64_t (*cmp)(struct perf_hpp_fmt *fmt,
259 struct hist_entry *a, struct hist_entry *b);
260 int64_t (*collapse)(struct perf_hpp_fmt *fmt,
261 struct hist_entry *a, struct hist_entry *b);
262 int64_t (*sort)(struct perf_hpp_fmt *fmt,
263 struct hist_entry *a, struct hist_entry *b);
264 bool (*equal)(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);
265 void (*free)(struct perf_hpp_fmt *fmt);
267 struct list_head list;
268 struct list_head sort_list;
269 bool elide;
270 int len;
271 int user_len;
272 int idx;
273 int level;
276 struct perf_hpp_list {
277 struct list_head fields;
278 struct list_head sorts;
280 int nr_header_lines;
281 int need_collapse;
282 int parent;
283 int sym;
284 int dso;
285 int socket;
286 int thread;
287 int comm;
290 extern struct perf_hpp_list perf_hpp_list;
292 struct perf_hpp_list_node {
293 struct list_head list;
294 struct perf_hpp_list hpp;
295 int level;
296 bool skip;
299 void perf_hpp_list__column_register(struct perf_hpp_list *list,
300 struct perf_hpp_fmt *format);
301 void perf_hpp_list__register_sort_field(struct perf_hpp_list *list,
302 struct perf_hpp_fmt *format);
303 void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,
304 struct perf_hpp_fmt *format);
306 static inline void perf_hpp__column_register(struct perf_hpp_fmt *format)
308 perf_hpp_list__column_register(&perf_hpp_list, format);
311 static inline void perf_hpp__register_sort_field(struct perf_hpp_fmt *format)
313 perf_hpp_list__register_sort_field(&perf_hpp_list, format);
316 static inline void perf_hpp__prepend_sort_field(struct perf_hpp_fmt *format)
318 perf_hpp_list__prepend_sort_field(&perf_hpp_list, format);
321 #define perf_hpp_list__for_each_format(_list, format) \
322 list_for_each_entry(format, &(_list)->fields, list)
324 #define perf_hpp_list__for_each_format_safe(_list, format, tmp) \
325 list_for_each_entry_safe(format, tmp, &(_list)->fields, list)
327 #define perf_hpp_list__for_each_sort_list(_list, format) \
328 list_for_each_entry(format, &(_list)->sorts, sort_list)
330 #define perf_hpp_list__for_each_sort_list_safe(_list, format, tmp) \
331 list_for_each_entry_safe(format, tmp, &(_list)->sorts, sort_list)
333 #define hists__for_each_format(hists, format) \
334 perf_hpp_list__for_each_format((hists)->hpp_list, fmt)
336 #define hists__for_each_sort_list(hists, format) \
337 perf_hpp_list__for_each_sort_list((hists)->hpp_list, fmt)
339 extern struct perf_hpp_fmt perf_hpp__format[];
341 enum {
342 /* Matches perf_hpp__format array. */
343 PERF_HPP__OVERHEAD,
344 PERF_HPP__OVERHEAD_SYS,
345 PERF_HPP__OVERHEAD_US,
346 PERF_HPP__OVERHEAD_GUEST_SYS,
347 PERF_HPP__OVERHEAD_GUEST_US,
348 PERF_HPP__OVERHEAD_ACC,
349 PERF_HPP__SAMPLES,
350 PERF_HPP__PERIOD,
352 PERF_HPP__MAX_INDEX
355 void perf_hpp__init(void);
356 void perf_hpp__column_unregister(struct perf_hpp_fmt *format);
357 void perf_hpp__cancel_cumulate(void);
358 void perf_hpp__setup_output_field(struct perf_hpp_list *list);
359 void perf_hpp__reset_output_field(struct perf_hpp_list *list);
360 void perf_hpp__append_sort_keys(struct perf_hpp_list *list);
361 int perf_hpp__setup_hists_formats(struct perf_hpp_list *list,
362 struct perf_evlist *evlist);
365 bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
366 bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *format);
367 bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists);
368 bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt);
369 bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt);
370 bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt);
371 bool perf_hpp__is_thread_entry(struct perf_hpp_fmt *fmt);
372 bool perf_hpp__is_comm_entry(struct perf_hpp_fmt *fmt);
373 bool perf_hpp__is_dso_entry(struct perf_hpp_fmt *fmt);
374 bool perf_hpp__is_sym_entry(struct perf_hpp_fmt *fmt);
376 struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt);
378 int hist_entry__filter(struct hist_entry *he, int type, const void *arg);
380 static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format,
381 struct hists *hists)
383 if (format->elide)
384 return true;
386 if (perf_hpp__is_dynamic_entry(format) &&
387 !perf_hpp__defined_dynamic_entry(format, hists))
388 return true;
390 return false;
393 void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
394 void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists);
395 void perf_hpp__set_user_width(const char *width_list_str);
396 void hists__reset_column_width(struct hists *hists);
398 typedef u64 (*hpp_field_fn)(struct hist_entry *he);
399 typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
400 typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
402 int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
403 struct hist_entry *he, hpp_field_fn get_field,
404 const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);
405 int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
406 struct hist_entry *he, hpp_field_fn get_field,
407 const char *fmtstr, hpp_snprint_fn print_fn, bool fmt_percent);
409 static inline void advance_hpp(struct perf_hpp *hpp, int inc)
411 hpp->buf += inc;
412 hpp->size -= inc;
415 static inline size_t perf_hpp__use_color(void)
417 return !symbol_conf.field_sep;
420 static inline size_t perf_hpp__color_overhead(void)
422 return perf_hpp__use_color() ?
423 (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
424 : 0;
427 struct perf_evlist;
429 struct hist_browser_timer {
430 void (*timer)(void *arg);
431 void *arg;
432 int refresh;
435 struct annotation_options;
436 struct res_sample;
438 enum rstype {
439 A_NORMAL,
440 A_ASM,
441 A_SOURCE
444 #ifdef HAVE_SLANG_SUPPORT
445 #include "../ui/keysyms.h"
446 void attr_to_script(char *buf, struct perf_event_attr *attr);
448 int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel,
449 struct hist_browser_timer *hbt,
450 struct annotation_options *annotation_opts);
452 int hist_entry__tui_annotate(struct hist_entry *he, struct perf_evsel *evsel,
453 struct hist_browser_timer *hbt,
454 struct annotation_options *annotation_opts);
456 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
457 struct hist_browser_timer *hbt,
458 float min_pcnt,
459 struct perf_env *env,
460 bool warn_lost_event,
461 struct annotation_options *annotation_options);
463 int script_browse(const char *script_opt, struct perf_evsel *evsel);
465 void run_script(char *cmd);
466 int res_sample_browse(struct res_sample *res_samples, int num_res,
467 struct perf_evsel *evsel, enum rstype rstype);
468 void res_sample_init(void);
469 #else
470 static inline
471 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused,
472 const char *help __maybe_unused,
473 struct hist_browser_timer *hbt __maybe_unused,
474 float min_pcnt __maybe_unused,
475 struct perf_env *env __maybe_unused,
476 bool warn_lost_event __maybe_unused,
477 struct annotation_options *annotation_options __maybe_unused)
479 return 0;
481 static inline int map_symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
482 struct perf_evsel *evsel __maybe_unused,
483 struct hist_browser_timer *hbt __maybe_unused,
484 struct annotation_options *annotation_options __maybe_unused)
486 return 0;
489 static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
490 struct perf_evsel *evsel __maybe_unused,
491 struct hist_browser_timer *hbt __maybe_unused,
492 struct annotation_options *annotation_opts __maybe_unused)
494 return 0;
497 static inline int script_browse(const char *script_opt __maybe_unused,
498 struct perf_evsel *evsel __maybe_unused)
500 return 0;
503 static inline int res_sample_browse(struct res_sample *res_samples __maybe_unused,
504 int num_res __maybe_unused,
505 struct perf_evsel *evsel __maybe_unused,
506 enum rstype rstype __maybe_unused)
508 return 0;
511 static inline void res_sample_init(void) {}
513 #define K_LEFT -1000
514 #define K_RIGHT -2000
515 #define K_SWITCH_INPUT_DATA -3000
516 #endif
518 unsigned int hists__sort_list_width(struct hists *hists);
519 unsigned int hists__overhead_width(struct hists *hists);
521 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
522 struct perf_sample *sample, bool nonany_branch_mode);
524 struct option;
525 int parse_filter_percentage(const struct option *opt, const char *arg, int unset);
526 int perf_hist_config(const char *var, const char *value);
528 void perf_hpp_list__init(struct perf_hpp_list *list);
530 enum hierarchy_move_dir {
531 HMD_NORMAL,
532 HMD_FORCE_SIBLING,
533 HMD_FORCE_CHILD,
536 struct rb_node *rb_hierarchy_last(struct rb_node *node);
537 struct rb_node *__rb_hierarchy_next(struct rb_node *node,
538 enum hierarchy_move_dir hmd);
539 struct rb_node *rb_hierarchy_prev(struct rb_node *node);
541 static inline struct rb_node *rb_hierarchy_next(struct rb_node *node)
543 return __rb_hierarchy_next(node, HMD_NORMAL);
546 #define HIERARCHY_INDENT 3
548 bool hist_entry__has_hierarchy_children(struct hist_entry *he, float limit);
549 int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...);
550 int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...);
551 int __hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp,
552 struct perf_hpp_list *hpp_list);
553 int hists__fprintf_headers(struct hists *hists, FILE *fp);
554 int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool show_freq);
556 static inline int hists__scnprintf_title(struct hists *hists, char *bf, size_t size)
558 return __hists__scnprintf_title(hists, bf, size, true);
561 #endif /* __PERF_HIST_H */