xref: /linux/tools/perf/util/hist.h (revision 5ea5880764cbb164afb17a62e76ca75dc371409d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_HIST_H
3 #define __PERF_HIST_H
4 
5 #include <linux/rbtree.h>
6 #include <linux/types.h>
7 #include "callchain.h"
8 #include "color.h"
9 #include "events_stats.h"
10 #include "evsel.h"
11 #include "map_symbol.h"
12 #include "mem-events.h"
13 #include "mutex.h"
14 #include "sample.h"
15 #include "spark.h"
16 #include "stat.h"
17 
18 struct addr_location;
19 struct mem_info;
20 struct kvm_info;
21 struct branch_info;
22 struct branch_stack;
23 struct block_info;
24 struct ui_progress;
25 
26 enum hist_filter {
27 	HIST_FILTER__DSO,
28 	HIST_FILTER__THREAD,
29 	HIST_FILTER__PARENT,
30 	HIST_FILTER__SYMBOL,
31 	HIST_FILTER__GUEST,
32 	HIST_FILTER__HOST,
33 	HIST_FILTER__SOCKET,
34 	HIST_FILTER__C2C,
35 	HIST_FILTER__PARALLELISM,
36 };
37 
38 typedef u16 filter_mask_t;
39 
40 enum hist_column {
41 	HISTC_SYMBOL,
42 	HISTC_TIME,
43 	HISTC_DSO,
44 	HISTC_THREAD,
45 	HISTC_TGID,
46 	HISTC_COMM,
47 	HISTC_COMM_NODIGIT,
48 	HISTC_CGROUP_ID,
49 	HISTC_CGROUP,
50 	HISTC_PARENT,
51 	HISTC_PARALLELISM,
52 	HISTC_CPU,
53 	HISTC_SOCKET,
54 	HISTC_SRCLINE,
55 	HISTC_SRCFILE,
56 	HISTC_MISPREDICT,
57 	HISTC_IN_TX,
58 	HISTC_ABORT,
59 	HISTC_SYMBOL_FROM,
60 	HISTC_SYMBOL_TO,
61 	HISTC_DSO_FROM,
62 	HISTC_DSO_TO,
63 	HISTC_LOCAL_WEIGHT,
64 	HISTC_GLOBAL_WEIGHT,
65 	HISTC_CODE_PAGE_SIZE,
66 	HISTC_MEM_DADDR_SYMBOL,
67 	HISTC_MEM_DADDR_DSO,
68 	HISTC_MEM_PHYS_DADDR,
69 	HISTC_MEM_DATA_PAGE_SIZE,
70 	HISTC_MEM_LOCKED,
71 	HISTC_MEM_TLB,
72 	HISTC_MEM_LVL,
73 	HISTC_MEM_SNOOP,
74 	HISTC_MEM_DCACHELINE,
75 	HISTC_MEM_IADDR_SYMBOL,
76 	HISTC_TRANSACTION,
77 	HISTC_CYCLES,
78 	HISTC_SRCLINE_FROM,
79 	HISTC_SRCLINE_TO,
80 	HISTC_TRACE,
81 	HISTC_SYM_SIZE,
82 	HISTC_DSO_SIZE,
83 	HISTC_SYMBOL_IPC,
84 	HISTC_MEM_BLOCKED,
85 	HISTC_LOCAL_INS_LAT,
86 	HISTC_GLOBAL_INS_LAT,
87 	HISTC_LOCAL_P_STAGE_CYC,
88 	HISTC_GLOBAL_P_STAGE_CYC,
89 	HISTC_ADDR_FROM,
90 	HISTC_ADDR_TO,
91 	HISTC_ADDR,
92 	HISTC_SIMD,
93 	HISTC_TYPE,
94 	HISTC_TYPE_OFFSET,
95 	HISTC_SYMBOL_OFFSET,
96 	HISTC_TYPE_CACHELINE,
97 	HISTC_CALLCHAIN_BRANCH_PREDICTED,
98 	HISTC_CALLCHAIN_BRANCH_ABORT,
99 	HISTC_CALLCHAIN_BRANCH_CYCLES,
100 	HISTC_NR_COLS, /* Last entry */
101 };
102 
103 struct thread;
104 struct dso;
105 
106 #define MEM_STAT_LEN  8
107 
108 struct he_mem_stat {
109 	/* meaning of entries depends on enum mem_stat_type */
110 	u64			entries[MEM_STAT_LEN];
111 };
112 
113 struct hists {
114 	struct rb_root_cached	entries_in_array[2];
115 	struct rb_root_cached	*entries_in;
116 	struct rb_root_cached	entries;
117 	struct rb_root_cached	entries_collapsed;
118 	u64			nr_entries;
119 	u64			nr_non_filtered_entries;
120 	u64			callchain_period;
121 	u64			callchain_non_filtered_period;
122 	u64			callchain_latency;
123 	u64			callchain_non_filtered_latency;
124 	struct thread		*thread_filter;
125 	const struct dso	*dso_filter;
126 	const char		*uid_filter_str;
127 	const char		*symbol_filter_str;
128 	unsigned long		*parallelism_filter;
129 	struct mutex		lock;
130 	struct hists_stats	stats;
131 	u64			event_stream;
132 	u16			col_len[HISTC_NR_COLS];
133 	bool			has_callchains;
134 	int			socket_filter;
135 	struct perf_hpp_list	*hpp_list;
136 	struct list_head	hpp_formats;
137 	int			nr_hpp_node;
138 	int			nr_mem_stats;
139 	enum mem_stat_type	*mem_stat_types;
140 	struct he_mem_stat	*mem_stat_total;
141 };
142 
143 #define hists__has(__h, __f) (__h)->hpp_list->__f
144 
145 struct hist_entry_iter;
146 
147 struct hist_iter_ops {
148 	int (*prepare_entry)(struct hist_entry_iter *, struct addr_location *);
149 	int (*add_single_entry)(struct hist_entry_iter *, struct addr_location *);
150 	int (*next_entry)(struct hist_entry_iter *, struct addr_location *);
151 	int (*add_next_entry)(struct hist_entry_iter *, struct addr_location *);
152 	int (*finish_entry)(struct hist_entry_iter *, struct addr_location *);
153 };
154 
155 struct hist_entry_iter {
156 	int total;
157 	int curr;
158 
159 	struct evsel *evsel;
160 	struct perf_sample *sample;
161 	struct hist_entry *he;
162 	struct symbol *parent;
163 
164 	struct mem_info *mi;
165 	struct branch_info *bi;
166 	struct hist_entry **he_cache;
167 
168 	const struct hist_iter_ops *ops;
169 	/* user-defined callback function (optional) */
170 	int (*add_entry_cb)(struct hist_entry_iter *iter,
171 			    struct addr_location *al, bool single, void *arg);
172 	bool hide_unresolved;
173 };
174 
175 extern const struct hist_iter_ops hist_iter_normal;
176 extern const struct hist_iter_ops hist_iter_branch;
177 extern const struct hist_iter_ops hist_iter_mem;
178 extern const struct hist_iter_ops hist_iter_cumulative;
179 
180 struct res_sample {
181 	u64 time;
182 	int cpu;
183 	int tid;
184 };
185 
186 struct he_stat {
187 	u64			period;
188 	/*
189 	 * Period re-scaled from CPU time to wall-clock time (divided by the
190 	 * parallelism at the time of the sample). This represents effect of
191 	 * the event on latency rather than CPU consumption.
192 	 */
193 	u64			latency;
194 	u64			period_sys;
195 	u64			period_us;
196 	u64			period_guest_sys;
197 	u64			period_guest_us;
198 	u64			weight1;
199 	u64			weight2;
200 	u64			weight3;
201 	u32			nr_events;
202 };
203 
204 struct namespace_id {
205 	u64			dev;
206 	u64			ino;
207 };
208 
209 struct hist_entry_diff {
210 	bool	computed;
211 	union {
212 		/* PERF_HPP__DELTA */
213 		double	period_ratio_delta;
214 
215 		/* PERF_HPP__RATIO */
216 		double	period_ratio;
217 
218 		/* HISTC_WEIGHTED_DIFF */
219 		s64	wdiff;
220 
221 		/* PERF_HPP_DIFF__CYCLES */
222 		s64	cycles;
223 	};
224 	struct stats	stats;
225 	unsigned long	svals[NUM_SPARKS];
226 };
227 
228 struct hist_entry_ops {
229 	void	*(*new)(size_t size);
230 	void	(*free)(void *ptr);
231 };
232 
233 /**
234  * struct hist_entry - histogram entry
235  *
236  * @row_offset - offset from the first callchain expanded to appear on screen
237  * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
238  */
239 struct hist_entry {
240 	struct rb_node		rb_node_in;
241 	struct rb_node		rb_node;
242 	union {
243 		struct list_head node;
244 		struct list_head head;
245 	} pairs;
246 	struct he_stat		stat;
247 	struct he_stat		*stat_acc;
248 	struct he_mem_stat	*mem_stat;
249 	struct map_symbol	ms;
250 	struct thread		*thread;
251 	struct comm		*comm;
252 	struct namespace_id	cgroup_id;
253 	u64			cgroup;
254 	u64			ip;
255 	u64			transaction;
256 	u64			code_page_size;
257 	u64			weight;
258 	u64			ins_lat;
259 	/** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */
260 	u64			weight3;
261 	s32			socket;
262 	s32			cpu;
263 	int			parallelism;
264 	int			mem_type_off;
265 	u8			cpumode;
266 	u8			depth;
267 	struct simd_flags	simd_flags;
268 
269 	/* We are added by hists__add_dummy_entry. */
270 	bool			dummy;
271 	bool			leaf;
272 
273 	char			level;
274 	filter_mask_t		filtered;
275 
276 	u16			callchain_size;
277 	union {
278 		/*
279 		 * Since perf diff only supports the stdio output, TUI
280 		 * fields are only accessed from perf report (or perf
281 		 * top).  So make it a union to reduce memory usage.
282 		 */
283 		struct hist_entry_diff	diff;
284 		struct /* for TUI */ {
285 			u16	row_offset;
286 			u16	nr_rows;
287 			bool	init_have_children;
288 			bool	unfolded;
289 			bool	has_children;
290 			bool	has_no_entry;
291 		};
292 	};
293 	char			*srcline;
294 	char			*srcfile;
295 	struct symbol		*parent;
296 	struct branch_info	*branch_info;
297 	long			time;
298 	struct hists		*hists;
299 	struct mem_info		*mem_info;
300 	struct block_info	*block_info;
301 	struct kvm_info		*kvm_info;
302 	void			*raw_data;
303 	u32			raw_size;
304 	int			num_res;
305 	struct res_sample	*res_samples;
306 	void			*trace_output;
307 	struct perf_hpp_list	*hpp_list;
308 	struct hist_entry	*parent_he;
309 	struct hist_entry_ops	*ops;
310 	struct annotated_data_type *mem_type;
311 	union {
312 		/* this is for hierarchical entry structure */
313 		struct {
314 			struct rb_root_cached	hroot_in;
315 			struct rb_root_cached   hroot_out;
316 		};				/* non-leaf entries */
317 		struct rb_root	sorted_chain;	/* leaf entry has callchains */
318 	};
319 	struct callchain_root	callchain[0]; /* must be last member */
320 };
321 
322 static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
323 {
324 	return he->callchain_size != 0;
325 }
326 
327 static inline bool hist_entry__has_pairs(struct hist_entry *he)
328 {
329 	return !list_empty(&he->pairs.node);
330 }
331 
332 static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
333 {
334 	if (hist_entry__has_pairs(he))
335 		return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
336 	return NULL;
337 }
338 
339 static inline void hist_entry__add_pair(struct hist_entry *pair,
340 					struct hist_entry *he)
341 {
342 	list_add_tail(&pair->pairs.node, &he->pairs.head);
343 }
344 
345 struct hist_entry *hists__add_entry(struct hists *hists,
346 				    struct addr_location *al,
347 				    struct symbol *parent,
348 				    struct branch_info *bi,
349 				    struct mem_info *mi,
350 				    struct kvm_info *ki,
351 				    struct perf_sample *sample,
352 				    bool sample_self);
353 
354 struct hist_entry *hists__add_entry_ops(struct hists *hists,
355 					struct hist_entry_ops *ops,
356 					struct addr_location *al,
357 					struct symbol *sym_parent,
358 					struct branch_info *bi,
359 					struct mem_info *mi,
360 					struct kvm_info *ki,
361 					struct perf_sample *sample,
362 					bool sample_self);
363 
364 struct hist_entry *hists__add_entry_block(struct hists *hists,
365 					  struct addr_location *al,
366 					  struct block_info *bi);
367 
368 int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
369 			 int max_stack_depth, void *arg);
370 
371 struct perf_hpp;
372 struct perf_hpp_fmt;
373 
374 int hist_entry__transaction_len(void);
375 int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size,
376 			      struct hists *hists);
377 int hist_entry__snprintf_alignment(struct hist_entry *he, struct perf_hpp *hpp,
378 				   struct perf_hpp_fmt *fmt, int printed);
379 int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size,
380 			     unsigned int width);
381 void hist_entry__delete(struct hist_entry *he);
382 
383 typedef int (*hists__resort_cb_t)(struct hist_entry *he, void *arg);
384 
385 void evsel__output_resort_cb(struct evsel *evsel, struct ui_progress *prog,
386 			     hists__resort_cb_t cb, void *cb_arg);
387 void evsel__output_resort(struct evsel *evsel, struct ui_progress *prog);
388 void hists__output_resort(struct hists *hists, struct ui_progress *prog);
389 void hists__output_resort_cb(struct hists *hists, struct ui_progress *prog,
390 			     hists__resort_cb_t cb);
391 int hists__collapse_resort(struct hists *hists, struct ui_progress *prog);
392 
393 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel);
394 void hists__delete_entries(struct hists *hists);
395 void hists__output_recalc_col_len(struct hists *hists, int max_rows);
396 
397 struct hist_entry *hists__get_entry(struct hists *hists, int idx);
398 
399 u64 hists__total_period(struct hists *hists);
400 u64 hists__total_latency(struct hists *hists);
401 void hists__reset_stats(struct hists *hists);
402 void hists__inc_stats(struct hists *hists, struct hist_entry *h);
403 void hists__inc_nr_events(struct hists *hists);
404 void hists__inc_nr_samples(struct hists *hists, bool filtered);
405 void hists__inc_nr_lost_samples(struct hists *hists, u32 lost);
406 void hists__inc_nr_dropped_samples(struct hists *hists, u32 lost);
407 
408 size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
409 		      int max_cols, float min_pcnt, FILE *fp,
410 		      bool ignore_callchains);
411 size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp);
412 
413 void hists__filter_by_dso(struct hists *hists);
414 void hists__filter_by_thread(struct hists *hists);
415 void hists__filter_by_symbol(struct hists *hists);
416 void hists__filter_by_socket(struct hists *hists);
417 void hists__filter_by_parallelism(struct hists *hists);
418 
419 static inline bool hists__has_filter(struct hists *hists)
420 {
421 	return hists->thread_filter || hists->dso_filter ||
422 		hists->symbol_filter_str || (hists->socket_filter > -1) ||
423 		hists->parallelism_filter;
424 }
425 
426 u16 hists__col_len(struct hists *hists, enum hist_column col);
427 void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len);
428 bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len);
429 void hists__reset_col_len(struct hists *hists);
430 void hists__calc_col_len(struct hists *hists, struct hist_entry *he);
431 
432 void hists__match(struct hists *leader, struct hists *other);
433 int hists__link(struct hists *leader, struct hists *other);
434 int hists__unlink(struct hists *hists);
435 
436 static inline float hist_entry__get_percent_limit(struct hist_entry *he)
437 {
438 	u64 period = he->stat.period;
439 	u64 total_period = hists__total_period(he->hists);
440 
441 	if (unlikely(total_period == 0))
442 		return 0;
443 
444 	if (symbol_conf.cumulate_callchain)
445 		period = he->stat_acc->period;
446 
447 	return period * 100.0 / total_period;
448 }
449 
450 struct hists_evsel {
451 	struct evsel evsel;
452 	struct hists	  hists;
453 };
454 
455 static inline struct evsel *hists_to_evsel(struct hists *hists)
456 {
457 	struct hists_evsel *hevsel = container_of(hists, struct hists_evsel, hists);
458 	return &hevsel->evsel;
459 }
460 
461 static inline struct hists *evsel__hists(struct evsel *evsel)
462 {
463 	struct hists_evsel *hevsel = (struct hists_evsel *)evsel;
464 	return &hevsel->hists;
465 }
466 
467 static __pure inline bool hists__has_callchains(struct hists *hists)
468 {
469 	return hists->has_callchains;
470 }
471 
472 int hists__init(void);
473 int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list);
474 
475 struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists);
476 
477 struct perf_hpp {
478 	char *buf;
479 	size_t size;
480 	const char *sep;
481 	void *ptr;
482 	bool skip;
483 };
484 
485 typedef int64_t (*perf_hpp_fmt_cmp_t)(
486 	struct perf_hpp_fmt *, struct hist_entry *, struct hist_entry *);
487 
488 struct perf_hpp_fmt {
489 	const char *name;
490 	int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
491 		      struct hists *hists, int line, int *span);
492 	int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
493 		     struct hists *hists);
494 	void (*init)(struct perf_hpp_fmt *fmt, struct hist_entry *he);
495 	int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
496 		     struct hist_entry *he);
497 	int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
498 		     struct hist_entry *he);
499 	perf_hpp_fmt_cmp_t cmp;
500 	perf_hpp_fmt_cmp_t collapse;
501 	perf_hpp_fmt_cmp_t sort;
502 	bool (*equal)(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b);
503 	void (*free)(struct perf_hpp_fmt *fmt);
504 
505 	struct list_head list;
506 	struct list_head sort_list;
507 	bool elide;
508 	int len;
509 	int user_len;
510 	int idx;
511 	int level;
512 };
513 
514 struct perf_hpp_list {
515 	struct list_head fields;
516 	struct list_head sorts;
517 
518 	int nr_header_lines;
519 	int need_collapse;
520 	int parent;
521 	int sym;
522 	int dso;
523 	int socket;
524 	int thread;
525 	int comm;
526 	int comm_nodigit;
527 };
528 
529 extern struct perf_hpp_list perf_hpp_list;
530 
531 struct perf_hpp_list_node {
532 	struct list_head	list;
533 	struct perf_hpp_list	hpp;
534 	int			level;
535 	bool			skip;
536 };
537 
538 void perf_hpp_list__column_register(struct perf_hpp_list *list,
539 				    struct perf_hpp_fmt *format);
540 void perf_hpp_list__register_sort_field(struct perf_hpp_list *list,
541 					struct perf_hpp_fmt *format);
542 void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,
543 				       struct perf_hpp_fmt *format);
544 
545 static inline void perf_hpp__column_register(struct perf_hpp_fmt *format)
546 {
547 	perf_hpp_list__column_register(&perf_hpp_list, format);
548 }
549 
550 static inline void perf_hpp__register_sort_field(struct perf_hpp_fmt *format)
551 {
552 	perf_hpp_list__register_sort_field(&perf_hpp_list, format);
553 }
554 
555 static inline void perf_hpp__prepend_sort_field(struct perf_hpp_fmt *format)
556 {
557 	perf_hpp_list__prepend_sort_field(&perf_hpp_list, format);
558 }
559 
560 #define perf_hpp_list__for_each_format(_list, format) \
561 	list_for_each_entry(format, &(_list)->fields, list)
562 
563 #define perf_hpp_list__for_each_format_safe(_list, format, tmp)	\
564 	list_for_each_entry_safe(format, tmp, &(_list)->fields, list)
565 
566 #define perf_hpp_list__for_each_sort_list(_list, format) \
567 	list_for_each_entry(format, &(_list)->sorts, sort_list)
568 
569 #define perf_hpp_list__for_each_sort_list_safe(_list, format, tmp)	\
570 	list_for_each_entry_safe(format, tmp, &(_list)->sorts, sort_list)
571 
572 #define hists__for_each_format(hists, format) \
573 	perf_hpp_list__for_each_format((hists)->hpp_list, format)
574 
575 #define hists__for_each_sort_list(hists, format) \
576 	perf_hpp_list__for_each_sort_list((hists)->hpp_list, format)
577 
578 extern struct perf_hpp_fmt perf_hpp__format[];
579 
580 enum {
581 	/* Matches perf_hpp__format array. */
582 	PERF_HPP__OVERHEAD,
583 	PERF_HPP__LATENCY,
584 	PERF_HPP__OVERHEAD_SYS,
585 	PERF_HPP__OVERHEAD_US,
586 	PERF_HPP__OVERHEAD_GUEST_SYS,
587 	PERF_HPP__OVERHEAD_GUEST_US,
588 	PERF_HPP__OVERHEAD_ACC,
589 	PERF_HPP__LATENCY_ACC,
590 	PERF_HPP__SAMPLES,
591 	PERF_HPP__PERIOD,
592 	PERF_HPP__WEIGHT1,
593 	PERF_HPP__WEIGHT2,
594 	PERF_HPP__WEIGHT3,
595 	PERF_HPP__MEM_STAT_OP,
596 	PERF_HPP__MEM_STAT_CACHE,
597 	PERF_HPP__MEM_STAT_MEMORY,
598 	PERF_HPP__MEM_STAT_SNOOP,
599 	PERF_HPP__MEM_STAT_DTLB,
600 
601 	PERF_HPP__MAX_INDEX
602 };
603 
604 void perf_hpp__init(void);
605 void perf_hpp__cancel_cumulate(struct evlist *evlist);
606 void perf_hpp__cancel_latency(struct evlist *evlist);
607 void perf_hpp__setup_output_field(struct perf_hpp_list *list);
608 void perf_hpp__reset_output_field(struct perf_hpp_list *list);
609 void perf_hpp__append_sort_keys(struct perf_hpp_list *list);
610 int perf_hpp__setup_hists_formats(struct perf_hpp_list *list,
611 				  struct evlist *evlist);
612 int perf_hpp__alloc_mem_stats(struct perf_hpp_list *list,
613 			      struct evlist *evlist);
614 
615 
616 bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
617 bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *format);
618 bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists);
619 bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt);
620 bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt);
621 bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt);
622 bool perf_hpp__is_thread_entry(struct perf_hpp_fmt *fmt);
623 bool perf_hpp__is_comm_entry(struct perf_hpp_fmt *fmt);
624 bool perf_hpp__is_dso_entry(struct perf_hpp_fmt *fmt);
625 bool perf_hpp__is_sym_entry(struct perf_hpp_fmt *fmt);
626 bool perf_hpp__is_parallelism_entry(struct perf_hpp_fmt *fmt);
627 
628 struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt);
629 
630 int hist_entry__filter(struct hist_entry *he, int type, const void *arg);
631 
632 static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format,
633 					 struct hists *hists)
634 {
635 	if (format->elide)
636 		return true;
637 
638 	if (perf_hpp__is_dynamic_entry(format) &&
639 	    !perf_hpp__defined_dynamic_entry(format, hists))
640 		return true;
641 
642 	return false;
643 }
644 
645 void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists);
646 void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists);
647 void perf_hpp__set_user_width(const char *width_list_str);
648 void hists__reset_column_width(struct hists *hists);
649 
650 enum perf_hpp_fmt_type {
651 	PERF_HPP_FMT_TYPE__RAW,
652 	PERF_HPP_FMT_TYPE__PERCENT,
653 	PERF_HPP_FMT_TYPE__LATENCY,
654 	PERF_HPP_FMT_TYPE__AVERAGE,
655 };
656 
657 typedef u64 (*hpp_field_fn)(struct hist_entry *he);
658 typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
659 typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...);
660 
661 int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
662 	     struct hist_entry *he, hpp_field_fn get_field,
663 	     const char *fmtstr, hpp_snprint_fn print_fn,
664 	     enum perf_hpp_fmt_type fmtype);
665 int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
666 		 struct hist_entry *he, hpp_field_fn get_field,
667 		 const char *fmtstr, hpp_snprint_fn print_fn,
668 		 enum perf_hpp_fmt_type fmtype);
669 int hpp__fmt_mem_stat(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
670 		      struct hist_entry *he, enum mem_stat_type mst,
671 		      const char *fmtstr, hpp_snprint_fn print_fn);
672 
673 static inline void advance_hpp(struct perf_hpp *hpp, int inc)
674 {
675 	hpp->buf  += inc;
676 	hpp->size -= inc;
677 }
678 
679 static inline size_t perf_hpp__use_color(void)
680 {
681 	return !symbol_conf.field_sep;
682 }
683 
684 static inline size_t perf_hpp__color_overhead(void)
685 {
686 	return perf_hpp__use_color() ?
687 	       (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
688 	       : 0;
689 }
690 
691 struct evlist;
692 
693 struct hist_browser_timer {
694 	void (*timer)(void *arg);
695 	void *arg;
696 	int refresh;
697 };
698 
699 enum rstype {
700 	A_NORMAL,
701 	A_ASM,
702 	A_SOURCE
703 };
704 
705 struct block_hist {
706 	struct hists		block_hists;
707 	struct perf_hpp_list	block_list;
708 	struct perf_hpp_fmt	block_fmt;
709 	int			block_idx;
710 	bool			valid;
711 	struct hist_entry	he;
712 };
713 
714 #define NO_ADDR 0
715 
716 #ifdef HAVE_SLANG_SUPPORT
717 #include "../ui/keysyms.h"
718 void attr_to_script(char *buf, struct perf_event_attr *attr);
719 
720 int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
721 			       struct evsel *evsel,
722 			       struct hist_browser_timer *hbt, u64 al_addr);
723 
724 int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel,
725 			     struct hist_browser_timer *hbt, u64 al_addr);
726 
727 int evlist__tui_browse_hists(struct evlist *evlist, const char *help, struct hist_browser_timer *hbt,
728 			     float min_pcnt, struct perf_env *env, bool warn_lost_event);
729 
730 int script_browse(const char *script_opt, struct evsel *evsel);
731 
732 void run_script(char *cmd);
733 int res_sample_browse(struct res_sample *res_samples, int num_res,
734 		      struct evsel *evsel, enum rstype rstype);
735 void res_sample_init(void);
736 
737 int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel,
738 			   float min_percent, struct perf_env *env);
739 #else
740 static inline
741 int evlist__tui_browse_hists(struct evlist *evlist __maybe_unused,
742 			     const char *help __maybe_unused,
743 			     struct hist_browser_timer *hbt __maybe_unused,
744 			     float min_pcnt __maybe_unused,
745 			     struct perf_env *env __maybe_unused,
746 			     bool warn_lost_event __maybe_unused)
747 {
748 	return 0;
749 }
750 static inline int __hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
751 					     struct map_symbol *ms __maybe_unused,
752 					     struct evsel *evsel __maybe_unused,
753 					     struct hist_browser_timer *hbt __maybe_unused,
754 					     u64 al_addr __maybe_unused)
755 {
756 	return 0;
757 }
758 
759 static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused,
760 					   struct evsel *evsel __maybe_unused,
761 					   struct hist_browser_timer *hbt __maybe_unused,
762 					   u64 al_addr __maybe_unused)
763 {
764 	return 0;
765 }
766 
767 static inline int script_browse(const char *script_opt __maybe_unused,
768 				struct evsel *evsel __maybe_unused)
769 {
770 	return 0;
771 }
772 
773 static inline int res_sample_browse(struct res_sample *res_samples __maybe_unused,
774 				    int num_res __maybe_unused,
775 				    struct evsel *evsel __maybe_unused,
776 				    enum rstype rstype __maybe_unused)
777 {
778 	return 0;
779 }
780 
781 static inline void res_sample_init(void) {}
782 
783 static inline int block_hists_tui_browse(struct block_hist *bh __maybe_unused,
784 					 struct evsel *evsel __maybe_unused,
785 					 float min_percent __maybe_unused,
786 					 struct perf_env *env __maybe_unused)
787 {
788 	return 0;
789 }
790 
791 #define K_LEFT  -1000
792 #define K_RIGHT -2000
793 #define K_SWITCH_INPUT_DATA -3000
794 #define K_RELOAD -4000
795 #endif
796 
797 unsigned int hists__sort_list_width(struct hists *hists);
798 unsigned int hists__overhead_width(struct hists *hists);
799 
800 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
801 			  struct perf_sample *sample, bool nonany_branch_mode,
802 			  u64 *total_cycles, struct evsel *evsel);
803 
804 struct option;
805 int parse_filter_percentage(const struct option *opt, const char *arg, int unset);
806 int perf_hist_config(const char *var, const char *value);
807 
808 void perf_hpp_list__init(struct perf_hpp_list *list);
809 
810 enum hierarchy_move_dir {
811 	HMD_NORMAL,
812 	HMD_FORCE_SIBLING,
813 	HMD_FORCE_CHILD,
814 };
815 
816 struct rb_node *rb_hierarchy_last(struct rb_node *node);
817 struct rb_node *__rb_hierarchy_next(struct rb_node *node,
818 				    enum hierarchy_move_dir hmd);
819 struct rb_node *rb_hierarchy_prev(struct rb_node *node);
820 
821 static inline struct rb_node *rb_hierarchy_next(struct rb_node *node)
822 {
823 	return __rb_hierarchy_next(node, HMD_NORMAL);
824 }
825 
826 #define HIERARCHY_INDENT  3
827 
828 bool hist_entry__has_hierarchy_children(struct hist_entry *he, float limit);
829 int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...);
830 int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...);
831 int __hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp,
832 			   struct perf_hpp_list *hpp_list);
833 int hists__fprintf_headers(struct hists *hists, FILE *fp);
834 int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool show_freq);
835 
836 static inline int hists__scnprintf_title(struct hists *hists, char *bf, size_t size)
837 {
838 	return __hists__scnprintf_title(hists, bf, size, true);
839 }
840 
841 #endif	/* __PERF_HIST_H */
842