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 merge_entries; 134 bool has_callchains; 135 int socket_filter; 136 struct perf_hpp_list *hpp_list; 137 struct list_head hpp_formats; 138 int nr_hpp_node; 139 int nr_mem_stats; 140 enum mem_stat_type *mem_stat_types; 141 struct he_mem_stat *mem_stat_total; 142 }; 143 144 #define hists__has(__h, __f) (__h)->hpp_list->__f 145 146 struct hist_entry_iter; 147 148 struct hist_iter_ops { 149 int (*prepare_entry)(struct hist_entry_iter *, struct addr_location *); 150 int (*add_single_entry)(struct hist_entry_iter *, struct addr_location *); 151 int (*next_entry)(struct hist_entry_iter *, struct addr_location *); 152 int (*add_next_entry)(struct hist_entry_iter *, struct addr_location *); 153 int (*finish_entry)(struct hist_entry_iter *, struct addr_location *); 154 }; 155 156 struct hist_entry_iter { 157 int total; 158 int curr; 159 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 struct list_head *pos; 343 344 list_for_each(pos, &he->pairs.head) { 345 if (pos == &pair->pairs.node) 346 return; /* Already paired */ 347 } 348 list_move_tail(&pair->pairs.node, &he->pairs.head); 349 } 350 351 struct hist_entry *hists__add_entry(struct hists *hists, 352 struct addr_location *al, 353 struct symbol *parent, 354 struct branch_info *bi, 355 struct mem_info *mi, 356 struct kvm_info *ki, 357 struct perf_sample *sample, 358 bool sample_self); 359 360 struct hist_entry *hists__add_entry_ops(struct hists *hists, 361 struct hist_entry_ops *ops, 362 struct addr_location *al, 363 struct symbol *sym_parent, 364 struct branch_info *bi, 365 struct mem_info *mi, 366 struct kvm_info *ki, 367 struct perf_sample *sample, 368 bool sample_self); 369 370 struct hist_entry *hists__add_entry_block(struct hists *hists, 371 struct addr_location *al, 372 struct block_info *bi); 373 374 int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, 375 int max_stack_depth, void *arg); 376 377 struct perf_hpp; 378 struct perf_hpp_fmt; 379 380 int hist_entry__transaction_len(void); 381 int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size, 382 struct hists *hists); 383 int hist_entry__snprintf_alignment(struct hist_entry *he, struct perf_hpp *hpp, 384 struct perf_hpp_fmt *fmt, int printed); 385 int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, 386 unsigned int width); 387 void hist_entry__delete(struct hist_entry *he); 388 389 typedef int (*hists__resort_cb_t)(struct hist_entry *he, void *arg); 390 391 void evsel__output_resort_cb(struct evsel *evsel, struct ui_progress *prog, 392 hists__resort_cb_t cb, void *cb_arg); 393 void evsel__output_resort(struct evsel *evsel, struct ui_progress *prog); 394 void hists__output_resort(struct hists *hists, struct ui_progress *prog); 395 void hists__output_resort_cb(struct hists *hists, struct ui_progress *prog, 396 hists__resort_cb_t cb); 397 int hists__collapse_resort(struct hists *hists, struct ui_progress *prog); 398 399 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel); 400 void hists__delete_entries(struct hists *hists); 401 void hists__delete_all_entries(struct hists *hists); 402 void hists__output_recalc_col_len(struct hists *hists, int max_rows); 403 404 struct hist_entry *hists__get_entry(struct hists *hists, int idx); 405 406 u64 hists__total_period(struct hists *hists); 407 u64 hists__total_latency(struct hists *hists); 408 void hists__reset_stats(struct hists *hists); 409 void hists__inc_stats(struct hists *hists, struct hist_entry *h); 410 void hists__inc_nr_events(struct hists *hists); 411 void hists__inc_nr_samples(struct hists *hists, bool filtered); 412 void hists__inc_nr_lost_samples(struct hists *hists, u32 lost); 413 void hists__inc_nr_dropped_samples(struct hists *hists, u32 lost); 414 415 size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, 416 int max_cols, float min_pcnt, FILE *fp, 417 bool ignore_callchains); 418 size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp); 419 420 void hists__filter_by_dso(struct hists *hists); 421 void hists__filter_by_thread(struct hists *hists); 422 void hists__filter_by_symbol(struct hists *hists); 423 void hists__filter_by_socket(struct hists *hists); 424 void hists__filter_by_parallelism(struct hists *hists); 425 426 static inline bool hists__has_filter(struct hists *hists) 427 { 428 return hists->thread_filter || hists->dso_filter || 429 hists->symbol_filter_str || (hists->socket_filter > -1) || 430 hists->parallelism_filter; 431 } 432 433 u16 hists__col_len(struct hists *hists, enum hist_column col); 434 void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len); 435 bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len); 436 void hists__reset_col_len(struct hists *hists); 437 void hists__calc_col_len(struct hists *hists, struct hist_entry *he); 438 439 void hists__match(struct hists *leader, struct hists *other); 440 int hists__link(struct hists *leader, struct hists *other); 441 int hists__unlink(struct hists *hists); 442 443 float hist_entry__get_percent_limit_merged(struct hist_entry *he); 444 void evlist__merge_hists_hybrid(struct evlist *evlist, bool refresh); 445 446 static inline float hist_entry__get_percent_limit(struct hist_entry *he) 447 { 448 u64 period = he->stat.period; 449 u64 total_period = hists__total_period(he->hists); 450 451 if (he->hists->merge_entries) 452 return hist_entry__get_percent_limit_merged(he); 453 454 if (unlikely(total_period == 0)) 455 return 0; 456 457 if (symbol_conf.cumulate_callchain) 458 period = he->stat_acc->period; 459 460 return period * 100.0 / total_period; 461 } 462 463 struct hists_evsel { 464 struct evsel evsel; 465 struct hists hists; 466 }; 467 468 static inline struct evsel *hists_to_evsel(struct hists *hists) 469 { 470 struct hists_evsel *hevsel = container_of(hists, struct hists_evsel, hists); 471 return &hevsel->evsel; 472 } 473 474 static inline struct hists *evsel__hists(struct evsel *evsel) 475 { 476 struct hists_evsel *hevsel = (struct hists_evsel *)evsel; 477 return &hevsel->hists; 478 } 479 480 static __pure inline bool hists__has_callchains(struct hists *hists) 481 { 482 return hists->has_callchains; 483 } 484 485 int hists__init(void); 486 int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list); 487 488 struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists); 489 490 struct perf_hpp { 491 char *buf; 492 size_t size; 493 const char *sep; 494 void *ptr; 495 bool skip; 496 }; 497 498 typedef int64_t (*perf_hpp_fmt_cmp_t)( 499 struct perf_hpp_fmt *, struct hist_entry *, struct hist_entry *); 500 501 struct perf_hpp_fmt { 502 const char *name; 503 int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 504 struct hists *hists, int line, int *span); 505 int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 506 struct hists *hists); 507 void (*init)(struct perf_hpp_fmt *fmt, struct hist_entry *he); 508 int (*color)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 509 struct hist_entry *he); 510 int (*entry)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 511 struct hist_entry *he); 512 perf_hpp_fmt_cmp_t cmp; 513 perf_hpp_fmt_cmp_t collapse; 514 perf_hpp_fmt_cmp_t sort; 515 bool (*equal)(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b); 516 void (*free)(struct perf_hpp_fmt *fmt); 517 518 struct list_head list; 519 struct list_head sort_list; 520 bool elide; 521 int len; 522 int user_len; 523 int idx; 524 int level; 525 }; 526 527 struct perf_hpp_list { 528 struct list_head fields; 529 struct list_head sorts; 530 531 int nr_header_lines; 532 int need_collapse; 533 int parent; 534 int sym; 535 int dso; 536 int socket; 537 int thread; 538 int comm; 539 int comm_nodigit; 540 }; 541 542 extern struct perf_hpp_list perf_hpp_list; 543 544 struct perf_hpp_list_node { 545 struct list_head list; 546 struct perf_hpp_list hpp; 547 int level; 548 bool skip; 549 }; 550 551 void perf_hpp_list__column_register(struct perf_hpp_list *list, 552 struct perf_hpp_fmt *format); 553 void perf_hpp_list__register_sort_field(struct perf_hpp_list *list, 554 struct perf_hpp_fmt *format); 555 void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list, 556 struct perf_hpp_fmt *format); 557 558 static inline void perf_hpp__column_register(struct perf_hpp_fmt *format) 559 { 560 perf_hpp_list__column_register(&perf_hpp_list, format); 561 } 562 563 static inline void perf_hpp__register_sort_field(struct perf_hpp_fmt *format) 564 { 565 perf_hpp_list__register_sort_field(&perf_hpp_list, format); 566 } 567 568 static inline void perf_hpp__prepend_sort_field(struct perf_hpp_fmt *format) 569 { 570 perf_hpp_list__prepend_sort_field(&perf_hpp_list, format); 571 } 572 573 #define perf_hpp_list__for_each_format(_list, format) \ 574 list_for_each_entry(format, &(_list)->fields, list) 575 576 #define perf_hpp_list__for_each_format_safe(_list, format, tmp) \ 577 list_for_each_entry_safe(format, tmp, &(_list)->fields, list) 578 579 #define perf_hpp_list__for_each_sort_list(_list, format) \ 580 list_for_each_entry(format, &(_list)->sorts, sort_list) 581 582 #define perf_hpp_list__for_each_sort_list_safe(_list, format, tmp) \ 583 list_for_each_entry_safe(format, tmp, &(_list)->sorts, sort_list) 584 585 #define hists__for_each_format(hists, format) \ 586 perf_hpp_list__for_each_format((hists)->hpp_list, format) 587 588 #define hists__for_each_sort_list(hists, format) \ 589 perf_hpp_list__for_each_sort_list((hists)->hpp_list, format) 590 591 extern struct perf_hpp_fmt perf_hpp__format[]; 592 593 enum { 594 /* Matches perf_hpp__format array. */ 595 PERF_HPP__OVERHEAD, 596 PERF_HPP__LATENCY, 597 PERF_HPP__OVERHEAD_SYS, 598 PERF_HPP__OVERHEAD_US, 599 PERF_HPP__OVERHEAD_GUEST_SYS, 600 PERF_HPP__OVERHEAD_GUEST_US, 601 PERF_HPP__OVERHEAD_ACC, 602 PERF_HPP__LATENCY_ACC, 603 PERF_HPP__SAMPLES, 604 PERF_HPP__PERIOD, 605 PERF_HPP__WEIGHT1, 606 PERF_HPP__WEIGHT2, 607 PERF_HPP__WEIGHT3, 608 PERF_HPP__MEM_STAT_OP, 609 PERF_HPP__MEM_STAT_CACHE, 610 PERF_HPP__MEM_STAT_MEMORY, 611 PERF_HPP__MEM_STAT_SNOOP, 612 PERF_HPP__MEM_STAT_DTLB, 613 614 PERF_HPP__MAX_INDEX 615 }; 616 617 void perf_hpp__init(void); 618 void perf_hpp__cancel_cumulate(struct evlist *evlist); 619 void perf_hpp__cancel_latency(struct evlist *evlist); 620 void perf_hpp__setup_output_field(struct perf_hpp_list *list); 621 void perf_hpp__reset_output_field(struct perf_hpp_list *list); 622 void perf_hpp__append_sort_keys(struct perf_hpp_list *list); 623 int perf_hpp__setup_hists_formats(struct perf_hpp_list *list, 624 struct evlist *evlist); 625 int perf_hpp__alloc_mem_stats(struct perf_hpp_list *list, 626 struct evlist *evlist); 627 628 629 bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); 630 bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *format); 631 bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists); 632 bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt); 633 bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt); 634 bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt); 635 bool perf_hpp__is_thread_entry(struct perf_hpp_fmt *fmt); 636 bool perf_hpp__is_comm_entry(struct perf_hpp_fmt *fmt); 637 bool perf_hpp__is_dso_entry(struct perf_hpp_fmt *fmt); 638 bool perf_hpp__is_sym_entry(struct perf_hpp_fmt *fmt); 639 bool perf_hpp__is_parallelism_entry(struct perf_hpp_fmt *fmt); 640 641 struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt); 642 643 int hist_entry__filter(struct hist_entry *he, int type, const void *arg); 644 645 static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format, 646 struct hists *hists) 647 { 648 if (format->elide) 649 return true; 650 651 if (perf_hpp__is_dynamic_entry(format) && 652 !perf_hpp__defined_dynamic_entry(format, hists)) 653 return true; 654 655 return false; 656 } 657 658 void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); 659 void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists); 660 void perf_hpp__set_user_width(const char *width_list_str); 661 void hists__reset_column_width(struct hists *hists); 662 663 enum perf_hpp_fmt_type { 664 PERF_HPP_FMT_TYPE__RAW, 665 PERF_HPP_FMT_TYPE__PERCENT, 666 PERF_HPP_FMT_TYPE__LATENCY, 667 PERF_HPP_FMT_TYPE__AVERAGE, 668 }; 669 670 typedef u64 (*hpp_field_fn)(struct hist_entry *he); 671 typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front); 672 typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...); 673 674 int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 675 struct hist_entry *he, hpp_field_fn get_field, 676 const char *fmtstr, hpp_snprint_fn print_fn, 677 enum perf_hpp_fmt_type fmtype); 678 int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 679 struct hist_entry *he, hpp_field_fn get_field, 680 const char *fmtstr, hpp_snprint_fn print_fn, 681 enum perf_hpp_fmt_type fmtype); 682 int hpp__fmt_mem_stat(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, 683 struct hist_entry *he, enum mem_stat_type mst, 684 const char *fmtstr, hpp_snprint_fn print_fn); 685 686 static inline void advance_hpp(struct perf_hpp *hpp, int inc) 687 { 688 hpp->buf += inc; 689 hpp->size -= inc; 690 } 691 692 static inline size_t perf_hpp__use_color(void) 693 { 694 return !symbol_conf.field_sep; 695 } 696 697 static inline size_t perf_hpp__color_overhead(void) 698 { 699 return perf_hpp__use_color() ? 700 (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX 701 : 0; 702 } 703 704 struct evlist; 705 706 struct hist_browser_timer { 707 void (*timer)(void *arg); 708 void *arg; 709 int refresh; 710 }; 711 712 enum rstype { 713 A_NORMAL, 714 A_ASM, 715 A_SOURCE 716 }; 717 718 struct block_hist { 719 struct hists block_hists; 720 struct perf_hpp_list block_list; 721 struct perf_hpp_fmt block_fmt; 722 int block_idx; 723 bool valid; 724 struct hist_entry he; 725 }; 726 727 #define NO_ADDR 0 728 729 #ifdef HAVE_SLANG_SUPPORT 730 void attr_to_script(char *buf, struct perf_event_attr *attr); 731 732 int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms, 733 struct evsel *evsel, 734 struct hist_browser_timer *hbt, u64 al_addr); 735 736 int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel, 737 struct hist_browser_timer *hbt, u64 al_addr); 738 739 int evlist__tui_browse_hists(struct evlist *evlist, const char *help, struct hist_browser_timer *hbt, 740 float min_pcnt, struct perf_env *env, bool warn_lost_event); 741 742 int script_browse(const char *script_opt, struct evsel *evsel); 743 744 void run_script(char *cmd); 745 int res_sample_browse(struct res_sample *res_samples, int num_res, 746 struct evsel *evsel, enum rstype rstype); 747 void res_sample_init(void); 748 749 int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel, 750 float min_percent, struct perf_env *env); 751 #else 752 static inline 753 int evlist__tui_browse_hists(struct evlist *evlist __maybe_unused, 754 const char *help __maybe_unused, 755 struct hist_browser_timer *hbt __maybe_unused, 756 float min_pcnt __maybe_unused, 757 struct perf_env *env __maybe_unused, 758 bool warn_lost_event __maybe_unused) 759 { 760 return 0; 761 } 762 static inline int __hist_entry__tui_annotate(struct hist_entry *he __maybe_unused, 763 struct map_symbol *ms __maybe_unused, 764 struct evsel *evsel __maybe_unused, 765 struct hist_browser_timer *hbt __maybe_unused, 766 u64 al_addr __maybe_unused) 767 { 768 return 0; 769 } 770 771 static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused, 772 struct evsel *evsel __maybe_unused, 773 struct hist_browser_timer *hbt __maybe_unused, 774 u64 al_addr __maybe_unused) 775 { 776 return 0; 777 } 778 779 static inline int script_browse(const char *script_opt __maybe_unused, 780 struct evsel *evsel __maybe_unused) 781 { 782 return 0; 783 } 784 785 static inline int res_sample_browse(struct res_sample *res_samples __maybe_unused, 786 int num_res __maybe_unused, 787 struct evsel *evsel __maybe_unused, 788 enum rstype rstype __maybe_unused) 789 { 790 return 0; 791 } 792 793 static inline void res_sample_init(void) {} 794 795 static inline int block_hists_tui_browse(struct block_hist *bh __maybe_unused, 796 struct evsel *evsel __maybe_unused, 797 float min_percent __maybe_unused, 798 struct perf_env *env __maybe_unused) 799 { 800 return 0; 801 } 802 #endif 803 804 unsigned int hists__sort_list_width(struct hists *hists); 805 unsigned int hists__overhead_width(struct hists *hists); 806 807 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, 808 struct perf_sample *sample, bool nonany_branch_mode, 809 u64 *total_cycles); 810 811 struct option; 812 int parse_filter_percentage(const struct option *opt, const char *arg, int unset); 813 int perf_hist_config(const char *var, const char *value); 814 815 void perf_hpp_list__init(struct perf_hpp_list *list); 816 817 enum hierarchy_move_dir { 818 HMD_NORMAL, 819 HMD_FORCE_SIBLING, 820 HMD_FORCE_CHILD, 821 }; 822 823 struct rb_node *rb_hierarchy_last(struct rb_node *node); 824 struct rb_node *__rb_hierarchy_next(struct rb_node *node, 825 enum hierarchy_move_dir hmd); 826 struct rb_node *rb_hierarchy_prev(struct rb_node *node); 827 828 static inline struct rb_node *rb_hierarchy_next(struct rb_node *node) 829 { 830 return __rb_hierarchy_next(node, HMD_NORMAL); 831 } 832 833 #define HIERARCHY_INDENT 3 834 835 bool hist_entry__has_hierarchy_children(struct hist_entry *he, float limit); 836 int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...); 837 int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...); 838 int __hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp, 839 struct perf_hpp_list *hpp_list); 840 int hists__fprintf_headers(struct hists *hists, FILE *fp); 841 int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool show_freq); 842 843 static inline int hists__scnprintf_title(struct hists *hists, char *bf, size_t size) 844 { 845 return __hists__scnprintf_title(hists, bf, size, true); 846 } 847 848 #endif /* __PERF_HIST_H */ 849