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