| 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_CGROUP_ID, |
| 48 | HISTC_CGROUP, |
| 49 | HISTC_PARENT, |
| 50 | HISTC_PARALLELISM, |
| 51 | HISTC_CPU, |
| 52 | HISTC_SOCKET, |
| 53 | HISTC_SRCLINE, |
| 54 | HISTC_SRCFILE, |
| 55 | HISTC_MISPREDICT, |
| 56 | HISTC_IN_TX, |
| 57 | HISTC_ABORT, |
| 58 | HISTC_SYMBOL_FROM, |
| 59 | HISTC_SYMBOL_TO, |
| 60 | HISTC_DSO_FROM, |
| 61 | HISTC_DSO_TO, |
| 62 | HISTC_LOCAL_WEIGHT, |
| 63 | HISTC_GLOBAL_WEIGHT, |
| 64 | HISTC_CODE_PAGE_SIZE, |
| 65 | HISTC_MEM_DADDR_SYMBOL, |
| 66 | HISTC_MEM_DADDR_DSO, |
| 67 | HISTC_MEM_PHYS_DADDR, |
| 68 | HISTC_MEM_DATA_PAGE_SIZE, |
| 69 | HISTC_MEM_LOCKED, |
| 70 | HISTC_MEM_TLB, |
| 71 | HISTC_MEM_LVL, |
| 72 | HISTC_MEM_SNOOP, |
| 73 | HISTC_MEM_DCACHELINE, |
| 74 | HISTC_MEM_IADDR_SYMBOL, |
| 75 | HISTC_TRANSACTION, |
| 76 | HISTC_CYCLES, |
| 77 | HISTC_SRCLINE_FROM, |
| 78 | HISTC_SRCLINE_TO, |
| 79 | HISTC_TRACE, |
| 80 | HISTC_SYM_SIZE, |
| 81 | HISTC_DSO_SIZE, |
| 82 | HISTC_SYMBOL_IPC, |
| 83 | HISTC_MEM_BLOCKED, |
| 84 | HISTC_LOCAL_INS_LAT, |
| 85 | HISTC_GLOBAL_INS_LAT, |
| 86 | HISTC_LOCAL_P_STAGE_CYC, |
| 87 | HISTC_GLOBAL_P_STAGE_CYC, |
| 88 | HISTC_ADDR_FROM, |
| 89 | HISTC_ADDR_TO, |
| 90 | HISTC_ADDR, |
| 91 | HISTC_SIMD, |
| 92 | HISTC_TYPE, |
| 93 | HISTC_TYPE_OFFSET, |
| 94 | HISTC_SYMBOL_OFFSET, |
| 95 | HISTC_TYPE_CACHELINE, |
| 96 | HISTC_CALLCHAIN_BRANCH_PREDICTED, |
| 97 | HISTC_CALLCHAIN_BRANCH_ABORT, |
| 98 | HISTC_CALLCHAIN_BRANCH_CYCLES, |
| 99 | HISTC_NR_COLS, /* Last entry */ |
| 100 | }; |
| 101 | |
| 102 | struct thread; |
| 103 | struct dso; |
| 104 | |
| 105 | #define MEM_STAT_LEN 8 |
| 106 | |
| 107 | struct he_mem_stat { |
| 108 | /* meaning of entries depends on enum mem_stat_type */ |
| 109 | u64 entries[MEM_STAT_LEN]; |
| 110 | }; |
| 111 | |
| 112 | struct hists { |
| 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; |
| 117 | u64 nr_entries; |
| 118 | u64 nr_non_filtered_entries; |
| 119 | u64 callchain_period; |
| 120 | u64 callchain_non_filtered_period; |
| 121 | u64 callchain_latency; |
| 122 | u64 callchain_non_filtered_latency; |
| 123 | struct thread *thread_filter; |
| 124 | const struct dso *dso_filter; |
| 125 | const char *uid_filter_str; |
| 126 | const char *symbol_filter_str; |
| 127 | unsigned long *parallelism_filter; |
| 128 | struct mutex lock; |
| 129 | struct hists_stats stats; |
| 130 | u64 event_stream; |
| 131 | u16 col_len[HISTC_NR_COLS]; |
| 132 | bool has_callchains; |
| 133 | int socket_filter; |
| 134 | struct perf_hpp_list *hpp_list; |
| 135 | struct list_head hpp_formats; |
| 136 | int nr_hpp_node; |
| 137 | int nr_mem_stats; |
| 138 | enum mem_stat_type *mem_stat_types; |
| 139 | struct he_mem_stat *mem_stat_total; |
| 140 | }; |
| 141 | |
| 142 | #define hists__has(__h, __f) (__h)->hpp_list->__f |
| 143 | |
| 144 | struct hist_entry_iter; |
| 145 | |
| 146 | struct 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 | |
| 154 | struct hist_entry_iter { |
| 155 | int total; |
| 156 | int curr; |
| 157 | |
| 158 | struct evsel *evsel; |
| 159 | struct perf_sample *sample; |
| 160 | struct hist_entry *he; |
| 161 | struct symbol *parent; |
| 162 | |
| 163 | struct mem_info *mi; |
| 164 | struct branch_info *bi; |
| 165 | struct hist_entry **he_cache; |
| 166 | |
| 167 | const struct hist_iter_ops *ops; |
| 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); |
| 171 | bool hide_unresolved; |
| 172 | }; |
| 173 | |
| 174 | extern const struct hist_iter_ops hist_iter_normal; |
| 175 | extern const struct hist_iter_ops hist_iter_branch; |
| 176 | extern const struct hist_iter_ops hist_iter_mem; |
| 177 | extern const struct hist_iter_ops hist_iter_cumulative; |
| 178 | |
| 179 | struct res_sample { |
| 180 | u64 time; |
| 181 | int cpu; |
| 182 | int tid; |
| 183 | }; |
| 184 | |
| 185 | struct he_stat { |
| 186 | u64 period; |
| 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; |
| 193 | u64 period_sys; |
| 194 | u64 period_us; |
| 195 | u64 period_guest_sys; |
| 196 | u64 period_guest_us; |
| 197 | u64 weight1; |
| 198 | u64 weight2; |
| 199 | u64 weight3; |
| 200 | u32 nr_events; |
| 201 | }; |
| 202 | |
| 203 | struct namespace_id { |
| 204 | u64 dev; |
| 205 | u64 ino; |
| 206 | }; |
| 207 | |
| 208 | struct 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 | |
| 227 | struct 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 | */ |
| 238 | struct 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; |
| 247 | struct he_mem_stat *mem_stat; |
| 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; |
| 255 | u64 code_page_size; |
| 256 | u64 weight; |
| 257 | u64 ins_lat; |
| 258 | u64 p_stage_cyc; |
| 259 | s32 socket; |
| 260 | s32 cpu; |
| 261 | int parallelism; |
| 262 | int mem_type_off; |
| 263 | u8 cpumode; |
| 264 | u8 depth; |
| 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; |
| 272 | filter_mask_t filtered; |
| 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 | |
| 320 | static __pure inline bool hist_entry__has_callchains(struct hist_entry *he) |
| 321 | { |
| 322 | return he->callchain_size != 0; |
| 323 | } |
| 324 | |
| 325 | static inline bool hist_entry__has_pairs(struct hist_entry *he) |
| 326 | { |
| 327 | return !list_empty(&he->pairs.node); |
| 328 | } |
| 329 | |
| 330 | static 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 | |
| 337 | static 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 | |
| 343 | struct 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, |
| 348 | struct kvm_info *ki, |
| 349 | struct perf_sample *sample, |
| 350 | bool sample_self); |
| 351 | |
| 352 | struct 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, |
| 358 | struct kvm_info *ki, |
| 359 | struct perf_sample *sample, |
| 360 | bool sample_self); |
| 361 | |
| 362 | struct hist_entry *hists__add_entry_block(struct hists *hists, |
| 363 | struct addr_location *al, |
| 364 | struct block_info *bi); |
| 365 | |
| 366 | int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, |
| 367 | int max_stack_depth, void *arg); |
| 368 | |
| 369 | struct perf_hpp; |
| 370 | struct perf_hpp_fmt; |
| 371 | |
| 372 | int hist_entry__transaction_len(void); |
| 373 | int hist_entry__sort_snprintf(struct hist_entry *he, char *bf, size_t size, |
| 374 | struct hists *hists); |
| 375 | int hist_entry__snprintf_alignment(struct hist_entry *he, struct perf_hpp *hpp, |
| 376 | struct perf_hpp_fmt *fmt, int printed); |
| 377 | int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, |
| 378 | unsigned int width); |
| 379 | void hist_entry__delete(struct hist_entry *he); |
| 380 | |
| 381 | typedef int (*hists__resort_cb_t)(struct hist_entry *he, void *arg); |
| 382 | |
| 383 | void evsel__output_resort_cb(struct evsel *evsel, struct ui_progress *prog, |
| 384 | hists__resort_cb_t cb, void *cb_arg); |
| 385 | void evsel__output_resort(struct evsel *evsel, struct ui_progress *prog); |
| 386 | void hists__output_resort(struct hists *hists, struct ui_progress *prog); |
| 387 | void hists__output_resort_cb(struct hists *hists, struct ui_progress *prog, |
| 388 | hists__resort_cb_t cb); |
| 389 | int hists__collapse_resort(struct hists *hists, struct ui_progress *prog); |
| 390 | |
| 391 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel); |
| 392 | void hists__delete_entries(struct hists *hists); |
| 393 | void hists__output_recalc_col_len(struct hists *hists, int max_rows); |
| 394 | |
| 395 | struct hist_entry *hists__get_entry(struct hists *hists, int idx); |
| 396 | |
| 397 | u64 hists__total_period(struct hists *hists); |
| 398 | u64 hists__total_latency(struct hists *hists); |
| 399 | void hists__reset_stats(struct hists *hists); |
| 400 | void hists__inc_stats(struct hists *hists, struct hist_entry *h); |
| 401 | void hists__inc_nr_events(struct hists *hists); |
| 402 | void hists__inc_nr_samples(struct hists *hists, bool filtered); |
| 403 | void hists__inc_nr_lost_samples(struct hists *hists, u32 lost); |
| 404 | void hists__inc_nr_dropped_samples(struct hists *hists, u32 lost); |
| 405 | |
| 406 | size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, |
| 407 | int max_cols, float min_pcnt, FILE *fp, |
| 408 | bool ignore_callchains); |
| 409 | size_t evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp); |
| 410 | |
| 411 | void hists__filter_by_dso(struct hists *hists); |
| 412 | void hists__filter_by_thread(struct hists *hists); |
| 413 | void hists__filter_by_symbol(struct hists *hists); |
| 414 | void hists__filter_by_socket(struct hists *hists); |
| 415 | void hists__filter_by_parallelism(struct hists *hists); |
| 416 | |
| 417 | static inline bool hists__has_filter(struct hists *hists) |
| 418 | { |
| 419 | return hists->thread_filter || hists->dso_filter || |
| 420 | hists->symbol_filter_str || (hists->socket_filter > -1) || |
| 421 | hists->parallelism_filter; |
| 422 | } |
| 423 | |
| 424 | u16 hists__col_len(struct hists *hists, enum hist_column col); |
| 425 | void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len); |
| 426 | bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len); |
| 427 | void hists__reset_col_len(struct hists *hists); |
| 428 | void hists__calc_col_len(struct hists *hists, struct hist_entry *he); |
| 429 | |
| 430 | void hists__match(struct hists *leader, struct hists *other); |
| 431 | int hists__link(struct hists *leader, struct hists *other); |
| 432 | int hists__unlink(struct hists *hists); |
| 433 | |
| 434 | static 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 | |
| 448 | struct hists_evsel { |
| 449 | struct evsel evsel; |
| 450 | struct hists hists; |
| 451 | }; |
| 452 | |
| 453 | static inline struct evsel *hists_to_evsel(struct hists *hists) |
| 454 | { |
| 455 | struct hists_evsel *hevsel = container_of(hists, struct hists_evsel, hists); |
| 456 | return &hevsel->evsel; |
| 457 | } |
| 458 | |
| 459 | static inline struct hists *evsel__hists(struct evsel *evsel) |
| 460 | { |
| 461 | struct hists_evsel *hevsel = (struct hists_evsel *)evsel; |
| 462 | return &hevsel->hists; |
| 463 | } |
| 464 | |
| 465 | static __pure inline bool hists__has_callchains(struct hists *hists) |
| 466 | { |
| 467 | return hists->has_callchains; |
| 468 | } |
| 469 | |
| 470 | int hists__init(void); |
| 471 | int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list); |
| 472 | |
| 473 | struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists); |
| 474 | |
| 475 | struct perf_hpp { |
| 476 | char *buf; |
| 477 | size_t size; |
| 478 | const char *sep; |
| 479 | void *ptr; |
| 480 | bool skip; |
| 481 | }; |
| 482 | |
| 483 | typedef int64_t (*perf_hpp_fmt_cmp_t)( |
| 484 | struct perf_hpp_fmt *, struct hist_entry *, struct hist_entry *); |
| 485 | |
| 486 | struct perf_hpp_fmt { |
| 487 | const char *name; |
| 488 | int (*header)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 489 | struct hists *hists, int line, int *span); |
| 490 | int (*width)(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 491 | struct hists *hists); |
| 492 | void (*init)(struct perf_hpp_fmt *fmt, struct hist_entry *he); |
| 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); |
| 497 | perf_hpp_fmt_cmp_t cmp; |
| 498 | perf_hpp_fmt_cmp_t collapse; |
| 499 | perf_hpp_fmt_cmp_t sort; |
| 500 | bool (*equal)(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b); |
| 501 | void (*free)(struct perf_hpp_fmt *fmt); |
| 502 | |
| 503 | struct list_head list; |
| 504 | struct list_head sort_list; |
| 505 | bool elide; |
| 506 | int len; |
| 507 | int user_len; |
| 508 | int idx; |
| 509 | int level; |
| 510 | }; |
| 511 | |
| 512 | struct perf_hpp_list { |
| 513 | struct list_head fields; |
| 514 | struct list_head sorts; |
| 515 | |
| 516 | int nr_header_lines; |
| 517 | int need_collapse; |
| 518 | int parent; |
| 519 | int sym; |
| 520 | int dso; |
| 521 | int socket; |
| 522 | int thread; |
| 523 | int comm; |
| 524 | }; |
| 525 | |
| 526 | extern struct perf_hpp_list perf_hpp_list; |
| 527 | |
| 528 | struct perf_hpp_list_node { |
| 529 | struct list_head list; |
| 530 | struct perf_hpp_list hpp; |
| 531 | int level; |
| 532 | bool skip; |
| 533 | }; |
| 534 | |
| 535 | void perf_hpp_list__column_register(struct perf_hpp_list *list, |
| 536 | struct perf_hpp_fmt *format); |
| 537 | void perf_hpp_list__register_sort_field(struct perf_hpp_list *list, |
| 538 | struct perf_hpp_fmt *format); |
| 539 | void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list, |
| 540 | struct perf_hpp_fmt *format); |
| 541 | |
| 542 | static inline void perf_hpp__column_register(struct perf_hpp_fmt *format) |
| 543 | { |
| 544 | perf_hpp_list__column_register(&perf_hpp_list, format); |
| 545 | } |
| 546 | |
| 547 | static 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 | |
| 552 | static 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 | |
| 557 | #define perf_hpp_list__for_each_format(_list, format) \ |
| 558 | list_for_each_entry(format, &(_list)->fields, list) |
| 559 | |
| 560 | #define perf_hpp_list__for_each_format_safe(_list, format, tmp) \ |
| 561 | list_for_each_entry_safe(format, tmp, &(_list)->fields, list) |
| 562 | |
| 563 | #define perf_hpp_list__for_each_sort_list(_list, format) \ |
| 564 | list_for_each_entry(format, &(_list)->sorts, sort_list) |
| 565 | |
| 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) |
| 568 | |
| 569 | #define hists__for_each_format(hists, format) \ |
| 570 | perf_hpp_list__for_each_format((hists)->hpp_list, format) |
| 571 | |
| 572 | #define hists__for_each_sort_list(hists, format) \ |
| 573 | perf_hpp_list__for_each_sort_list((hists)->hpp_list, format) |
| 574 | |
| 575 | extern struct perf_hpp_fmt perf_hpp__format[]; |
| 576 | |
| 577 | enum { |
| 578 | /* Matches perf_hpp__format array. */ |
| 579 | PERF_HPP__OVERHEAD, |
| 580 | PERF_HPP__LATENCY, |
| 581 | PERF_HPP__OVERHEAD_SYS, |
| 582 | PERF_HPP__OVERHEAD_US, |
| 583 | PERF_HPP__OVERHEAD_GUEST_SYS, |
| 584 | PERF_HPP__OVERHEAD_GUEST_US, |
| 585 | PERF_HPP__OVERHEAD_ACC, |
| 586 | PERF_HPP__LATENCY_ACC, |
| 587 | PERF_HPP__SAMPLES, |
| 588 | PERF_HPP__PERIOD, |
| 589 | PERF_HPP__WEIGHT1, |
| 590 | PERF_HPP__WEIGHT2, |
| 591 | PERF_HPP__WEIGHT3, |
| 592 | PERF_HPP__MEM_STAT_OP, |
| 593 | PERF_HPP__MEM_STAT_CACHE, |
| 594 | PERF_HPP__MEM_STAT_MEMORY, |
| 595 | PERF_HPP__MEM_STAT_SNOOP, |
| 596 | PERF_HPP__MEM_STAT_DTLB, |
| 597 | |
| 598 | PERF_HPP__MAX_INDEX |
| 599 | }; |
| 600 | |
| 601 | void perf_hpp__init(void); |
| 602 | void perf_hpp__cancel_cumulate(struct evlist *evlist); |
| 603 | void perf_hpp__cancel_latency(struct evlist *evlist); |
| 604 | void perf_hpp__setup_output_field(struct perf_hpp_list *list); |
| 605 | void perf_hpp__reset_output_field(struct perf_hpp_list *list); |
| 606 | void perf_hpp__append_sort_keys(struct perf_hpp_list *list); |
| 607 | int perf_hpp__setup_hists_formats(struct perf_hpp_list *list, |
| 608 | struct evlist *evlist); |
| 609 | int perf_hpp__alloc_mem_stats(struct perf_hpp_list *list, |
| 610 | struct evlist *evlist); |
| 611 | |
| 612 | |
| 613 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); |
| 614 | bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *format); |
| 615 | bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists); |
| 616 | bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt); |
| 617 | bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt); |
| 618 | bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt); |
| 619 | bool perf_hpp__is_thread_entry(struct perf_hpp_fmt *fmt); |
| 620 | bool perf_hpp__is_comm_entry(struct perf_hpp_fmt *fmt); |
| 621 | bool perf_hpp__is_dso_entry(struct perf_hpp_fmt *fmt); |
| 622 | bool perf_hpp__is_sym_entry(struct perf_hpp_fmt *fmt); |
| 623 | bool perf_hpp__is_parallelism_entry(struct perf_hpp_fmt *fmt); |
| 624 | |
| 625 | struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt); |
| 626 | |
| 627 | int hist_entry__filter(struct hist_entry *he, int type, const void *arg); |
| 628 | |
| 629 | static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format, |
| 630 | struct hists *hists) |
| 631 | { |
| 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; |
| 640 | } |
| 641 | |
| 642 | void perf_hpp__reset_width(struct perf_hpp_fmt *fmt, struct hists *hists); |
| 643 | void perf_hpp__reset_sort_width(struct perf_hpp_fmt *fmt, struct hists *hists); |
| 644 | void perf_hpp__set_user_width(const char *width_list_str); |
| 645 | void hists__reset_column_width(struct hists *hists); |
| 646 | |
| 647 | enum perf_hpp_fmt_type { |
| 648 | PERF_HPP_FMT_TYPE__RAW, |
| 649 | PERF_HPP_FMT_TYPE__PERCENT, |
| 650 | PERF_HPP_FMT_TYPE__LATENCY, |
| 651 | PERF_HPP_FMT_TYPE__AVERAGE, |
| 652 | }; |
| 653 | |
| 654 | typedef u64 (*hpp_field_fn)(struct hist_entry *he); |
| 655 | typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front); |
| 656 | typedef int (*hpp_snprint_fn)(struct perf_hpp *hpp, const char *fmt, ...); |
| 657 | |
| 658 | int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 659 | struct hist_entry *he, hpp_field_fn get_field, |
| 660 | const char *fmtstr, hpp_snprint_fn print_fn, |
| 661 | enum perf_hpp_fmt_type fmtype); |
| 662 | int hpp__fmt_acc(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, |
| 663 | struct hist_entry *he, hpp_field_fn get_field, |
| 664 | const char *fmtstr, hpp_snprint_fn print_fn, |
| 665 | enum perf_hpp_fmt_type fmtype); |
| 666 | int 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); |
| 669 | |
| 670 | static inline void advance_hpp(struct perf_hpp *hpp, int inc) |
| 671 | { |
| 672 | hpp->buf += inc; |
| 673 | hpp->size -= inc; |
| 674 | } |
| 675 | |
| 676 | static inline size_t perf_hpp__use_color(void) |
| 677 | { |
| 678 | return !symbol_conf.field_sep; |
| 679 | } |
| 680 | |
| 681 | static 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 | |
| 688 | struct evlist; |
| 689 | |
| 690 | struct hist_browser_timer { |
| 691 | void (*timer)(void *arg); |
| 692 | void *arg; |
| 693 | int refresh; |
| 694 | }; |
| 695 | |
| 696 | enum rstype { |
| 697 | A_NORMAL, |
| 698 | A_ASM, |
| 699 | A_SOURCE |
| 700 | }; |
| 701 | |
| 702 | struct 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 | }; |
| 710 | |
| 711 | #ifdef HAVE_SLANG_SUPPORT |
| 712 | #include "../ui/keysyms.h" |
| 713 | void attr_to_script(char *buf, struct perf_event_attr *attr); |
| 714 | |
| 715 | int map_symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel, |
| 716 | struct hist_browser_timer *hbt); |
| 717 | |
| 718 | int hist_entry__tui_annotate(struct hist_entry *he, struct evsel *evsel, |
| 719 | struct hist_browser_timer *hbt); |
| 720 | |
| 721 | int evlist__tui_browse_hists(struct evlist *evlist, const char *help, struct hist_browser_timer *hbt, |
| 722 | float min_pcnt, struct perf_env *env, bool warn_lost_event); |
| 723 | |
| 724 | int script_browse(const char *script_opt, struct evsel *evsel); |
| 725 | |
| 726 | void run_script(char *cmd); |
| 727 | int res_sample_browse(struct res_sample *res_samples, int num_res, |
| 728 | struct evsel *evsel, enum rstype rstype); |
| 729 | void res_sample_init(void); |
| 730 | |
| 731 | int block_hists_tui_browse(struct block_hist *bh, struct evsel *evsel, |
| 732 | float min_percent, struct perf_env *env); |
| 733 | #else |
| 734 | static inline |
| 735 | int 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, |
| 740 | bool warn_lost_event __maybe_unused) |
| 741 | { |
| 742 | return 0; |
| 743 | } |
| 744 | static inline int map_symbol__tui_annotate(struct map_symbol *ms __maybe_unused, |
| 745 | struct evsel *evsel __maybe_unused, |
| 746 | struct hist_browser_timer *hbt __maybe_unused) |
| 747 | { |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static inline int hist_entry__tui_annotate(struct hist_entry *he __maybe_unused, |
| 752 | struct evsel *evsel __maybe_unused, |
| 753 | struct hist_browser_timer *hbt __maybe_unused) |
| 754 | { |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | static inline int script_browse(const char *script_opt __maybe_unused, |
| 759 | struct evsel *evsel __maybe_unused) |
| 760 | { |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | static inline int res_sample_browse(struct res_sample *res_samples __maybe_unused, |
| 765 | int num_res __maybe_unused, |
| 766 | struct evsel *evsel __maybe_unused, |
| 767 | enum rstype rstype __maybe_unused) |
| 768 | { |
| 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | static inline void res_sample_init(void) {} |
| 773 | |
| 774 | static inline int block_hists_tui_browse(struct block_hist *bh __maybe_unused, |
| 775 | struct evsel *evsel __maybe_unused, |
| 776 | float min_percent __maybe_unused, |
| 777 | struct perf_env *env __maybe_unused) |
| 778 | { |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | #define K_LEFT -1000 |
| 783 | #define K_RIGHT -2000 |
| 784 | #define K_SWITCH_INPUT_DATA -3000 |
| 785 | #define K_RELOAD -4000 |
| 786 | #endif |
| 787 | |
| 788 | unsigned int hists__sort_list_width(struct hists *hists); |
| 789 | unsigned int hists__overhead_width(struct hists *hists); |
| 790 | |
| 791 | void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, |
| 792 | struct perf_sample *sample, bool nonany_branch_mode, |
| 793 | u64 *total_cycles, struct evsel *evsel); |
| 794 | |
| 795 | struct option; |
| 796 | int parse_filter_percentage(const struct option *opt, const char *arg, int unset); |
| 797 | int perf_hist_config(const char *var, const char *value); |
| 798 | |
| 799 | void perf_hpp_list__init(struct perf_hpp_list *list); |
| 800 | |
| 801 | enum hierarchy_move_dir { |
| 802 | HMD_NORMAL, |
| 803 | HMD_FORCE_SIBLING, |
| 804 | HMD_FORCE_CHILD, |
| 805 | }; |
| 806 | |
| 807 | struct rb_node *rb_hierarchy_last(struct rb_node *node); |
| 808 | struct rb_node *__rb_hierarchy_next(struct rb_node *node, |
| 809 | enum hierarchy_move_dir hmd); |
| 810 | struct rb_node *rb_hierarchy_prev(struct rb_node *node); |
| 811 | |
| 812 | static inline struct rb_node *rb_hierarchy_next(struct rb_node *node) |
| 813 | { |
| 814 | return __rb_hierarchy_next(node, HMD_NORMAL); |
| 815 | } |
| 816 | |
| 817 | #define HIERARCHY_INDENT 3 |
| 818 | |
| 819 | bool hist_entry__has_hierarchy_children(struct hist_entry *he, float limit); |
| 820 | int hpp_color_scnprintf(struct perf_hpp *hpp, const char *fmt, ...); |
| 821 | int __hpp__slsmg_color_printf(struct perf_hpp *hpp, const char *fmt, ...); |
| 822 | int __hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp, |
| 823 | struct perf_hpp_list *hpp_list); |
| 824 | int hists__fprintf_headers(struct hists *hists, FILE *fp); |
| 825 | int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool show_freq); |
| 826 | |
| 827 | static inline int hists__scnprintf_title(struct hists *hists, char *bf, size_t size) |
| 828 | { |
| 829 | return __hists__scnprintf_title(hists, bf, size, true); |
| 830 | } |
| 831 | |
| 832 | #endif /* __PERF_HIST_H */ |