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