1dd68ada2SJohn Kacur #ifndef __PERF_SORT_H 2dd68ada2SJohn Kacur #define __PERF_SORT_H 3dd68ada2SJohn Kacur #include "../builtin.h" 4dd68ada2SJohn Kacur 5dd68ada2SJohn Kacur #include "util.h" 6dd68ada2SJohn Kacur 7dd68ada2SJohn Kacur #include "color.h" 8dd68ada2SJohn Kacur #include <linux/list.h> 9dd68ada2SJohn Kacur #include "cache.h" 10dd68ada2SJohn Kacur #include <linux/rbtree.h> 11dd68ada2SJohn Kacur #include "symbol.h" 12dd68ada2SJohn Kacur #include "string.h" 13dd68ada2SJohn Kacur #include "callchain.h" 14dd68ada2SJohn Kacur #include "strlist.h" 15dd68ada2SJohn Kacur #include "values.h" 16dd68ada2SJohn Kacur 17dd68ada2SJohn Kacur #include "../perf.h" 18dd68ada2SJohn Kacur #include "debug.h" 19dd68ada2SJohn Kacur #include "header.h" 20dd68ada2SJohn Kacur 214b6ab94eSJosh Poimboeuf #include <subcmd/parse-options.h> 22dd68ada2SJohn Kacur #include "parse-events.h" 2314135663SNamhyung Kim #include "hist.h" 24dd68ada2SJohn Kacur #include "thread.h" 25dd68ada2SJohn Kacur 26dd68ada2SJohn Kacur extern regex_t parent_regex; 27edb7c60eSArnaldo Carvalho de Melo extern const char *sort_order; 28a7d945bcSNamhyung Kim extern const char *field_order; 29edb7c60eSArnaldo Carvalho de Melo extern const char default_parent_pattern[]; 30edb7c60eSArnaldo Carvalho de Melo extern const char *parent_pattern; 31edb7c60eSArnaldo Carvalho de Melo extern const char default_sort_order[]; 32b21484f1SGreg Price extern regex_t ignore_callees_regex; 33b21484f1SGreg Price extern int have_ignore_callees; 34dd68ada2SJohn Kacur extern int sort__need_collapse; 35b1447a54SNamhyung Kim extern int sort__has_dso; 36dd68ada2SJohn Kacur extern int sort__has_parent; 371af55640SNamhyung Kim extern int sort__has_sym; 382e7ea3abSKan Liang extern int sort__has_socket; 39cfd92dadSNamhyung Kim extern int sort__has_thread; 4055369fc1SNamhyung Kim extern enum sort_mode sort__mode; 41dd68ada2SJohn Kacur extern struct sort_entry sort_comm; 42dd68ada2SJohn Kacur extern struct sort_entry sort_dso; 43dd68ada2SJohn Kacur extern struct sort_entry sort_sym; 44dd68ada2SJohn Kacur extern struct sort_entry sort_parent; 45a68c2c58SStephane Eranian extern struct sort_entry sort_dso_from; 46a68c2c58SStephane Eranian extern struct sort_entry sort_dso_to; 47a68c2c58SStephane Eranian extern struct sort_entry sort_sym_from; 48a68c2c58SStephane Eranian extern struct sort_entry sort_sym_to; 49a4fb581bSFrederic Weisbecker extern enum sort_type sort__first_dimension; 50228f14f2SYunlong Song extern const char default_mem_sort_order[]; 51dd68ada2SJohn Kacur 52b24c28f7SNamhyung Kim struct he_stat { 53b24c28f7SNamhyung Kim u64 period; 54b24c28f7SNamhyung Kim u64 period_sys; 55b24c28f7SNamhyung Kim u64 period_us; 56b24c28f7SNamhyung Kim u64 period_guest_sys; 57b24c28f7SNamhyung Kim u64 period_guest_us; 5805484298SAndi Kleen u64 weight; 59b24c28f7SNamhyung Kim u32 nr_events; 60b24c28f7SNamhyung Kim }; 61b24c28f7SNamhyung Kim 6296c47f19SJiri Olsa struct hist_entry_diff { 6396c47f19SJiri Olsa bool computed; 64a0b404f4SNamhyung Kim union { 6596c47f19SJiri Olsa /* PERF_HPP__DELTA */ 6696c47f19SJiri Olsa double period_ratio_delta; 6796c47f19SJiri Olsa 6896c47f19SJiri Olsa /* PERF_HPP__RATIO */ 6996c47f19SJiri Olsa double period_ratio; 7081d5f958SJiri Olsa 7181d5f958SJiri Olsa /* HISTC_WEIGHTED_DIFF */ 7281d5f958SJiri Olsa s64 wdiff; 7396c47f19SJiri Olsa }; 74a0b404f4SNamhyung Kim }; 7596c47f19SJiri Olsa 760f0cbf7aSArnaldo Carvalho de Melo /** 770f0cbf7aSArnaldo Carvalho de Melo * struct hist_entry - histogram entry 780f0cbf7aSArnaldo Carvalho de Melo * 790f0cbf7aSArnaldo Carvalho de Melo * @row_offset - offset from the first callchain expanded to appear on screen 800f0cbf7aSArnaldo Carvalho de Melo * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding 810f0cbf7aSArnaldo Carvalho de Melo */ 82dd68ada2SJohn Kacur struct hist_entry { 831980c2ebSArnaldo Carvalho de Melo struct rb_node rb_node_in; 84dd68ada2SJohn Kacur struct rb_node rb_node; 85b821c732SArnaldo Carvalho de Melo union { 86b821c732SArnaldo Carvalho de Melo struct list_head node; 87b821c732SArnaldo Carvalho de Melo struct list_head head; 88b821c732SArnaldo Carvalho de Melo } pairs; 89b24c28f7SNamhyung Kim struct he_stat stat; 90f8be1c8cSNamhyung Kim struct he_stat *stat_acc; 9159fd5306SArnaldo Carvalho de Melo struct map_symbol ms; 92a5e29acaSArnaldo Carvalho de Melo struct thread *thread; 934dfced35SNamhyung Kim struct comm *comm; 94dd68ada2SJohn Kacur u64 ip; 95475eeab9SAndi Kleen u64 transaction; 960c4c4debSKan Liang s32 socket; 97f60f3593SArun Sharma s32 cpu; 987365be55SDon Zickus u8 cpumode; 99aef810ecSNamhyung Kim u8 depth; 1000f0cbf7aSArnaldo Carvalho de Melo 101e0af43d2SJiri Olsa /* We are added by hists__add_dummy_entry. */ 102e0af43d2SJiri Olsa bool dummy; 103aef810ecSNamhyung Kim bool leaf; 104e0af43d2SJiri Olsa 105dd68ada2SJohn Kacur char level; 106a5e29acaSArnaldo Carvalho de Melo u8 filtered; 10729750821SNamhyung Kim union { 10829750821SNamhyung Kim /* 10929750821SNamhyung Kim * Since perf diff only supports the stdio output, TUI 11029750821SNamhyung Kim * fields are only accessed from perf report (or perf 11129750821SNamhyung Kim * top). So make it an union to reduce memory usage. 11229750821SNamhyung Kim */ 11329750821SNamhyung Kim struct hist_entry_diff diff; 11429750821SNamhyung Kim struct /* for TUI */ { 11529750821SNamhyung Kim u16 row_offset; 11629750821SNamhyung Kim u16 nr_rows; 117d8a0f800SNamhyung Kim bool init_have_children; 1183698dab1SNamhyung Kim bool unfolded; 1193698dab1SNamhyung Kim bool has_children; 12079dded87SNamhyung Kim bool has_no_entry; 12129750821SNamhyung Kim }; 12229750821SNamhyung Kim }; 123409a8be6SArnaldo Carvalho de Melo char *srcline; 12431191a85SAndi Kleen char *srcfile; 125439d473bSArnaldo Carvalho de Melo struct symbol *parent; 126b5387528SRoberto Agostino Vitillo struct branch_info *branch_info; 127ae359f19SJiri Olsa struct hists *hists; 12898a3b32cSStephane Eranian struct mem_info *mem_info; 12972392834SNamhyung Kim void *raw_data; 13072392834SNamhyung Kim u32 raw_size; 13160517d28SNamhyung Kim void *trace_output; 132aef810ecSNamhyung Kim struct perf_hpp_fmt *fmt; 1331b2dbbf4SNamhyung Kim struct perf_hpp_list *hpp_list; 134aef810ecSNamhyung Kim struct hist_entry *parent_he; 135aef810ecSNamhyung Kim union { 136aef810ecSNamhyung Kim /* this is for hierarchical entry structure */ 137aef810ecSNamhyung Kim struct { 138aef810ecSNamhyung Kim struct rb_root hroot_in; 139aef810ecSNamhyung Kim struct rb_root hroot_out; 140aef810ecSNamhyung Kim }; /* non-leaf entries */ 141aef810ecSNamhyung Kim struct rb_root sorted_chain; /* leaf entry has callchains */ 142aef810ecSNamhyung Kim }; 14398a3b32cSStephane Eranian struct callchain_root callchain[0]; /* must be last member */ 14486a9eee0SArnaldo Carvalho de Melo }; 145dd68ada2SJohn Kacur 146b821c732SArnaldo Carvalho de Melo static inline bool hist_entry__has_pairs(struct hist_entry *he) 147b821c732SArnaldo Carvalho de Melo { 148b821c732SArnaldo Carvalho de Melo return !list_empty(&he->pairs.node); 149b821c732SArnaldo Carvalho de Melo } 150b821c732SArnaldo Carvalho de Melo 151b821c732SArnaldo Carvalho de Melo static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he) 152b821c732SArnaldo Carvalho de Melo { 153b821c732SArnaldo Carvalho de Melo if (hist_entry__has_pairs(he)) 154b821c732SArnaldo Carvalho de Melo return list_entry(he->pairs.node.next, struct hist_entry, pairs.node); 155b821c732SArnaldo Carvalho de Melo return NULL; 156b821c732SArnaldo Carvalho de Melo } 157b821c732SArnaldo Carvalho de Melo 1584d23322aSJiri Olsa static inline void hist_entry__add_pair(struct hist_entry *pair, 1594d23322aSJiri Olsa struct hist_entry *he) 160b821c732SArnaldo Carvalho de Melo { 1614d23322aSJiri Olsa list_add_tail(&pair->pairs.node, &he->pairs.head); 162b821c732SArnaldo Carvalho de Melo } 163b821c732SArnaldo Carvalho de Melo 16414135663SNamhyung Kim static inline float hist_entry__get_percent_limit(struct hist_entry *he) 16514135663SNamhyung Kim { 16614135663SNamhyung Kim u64 period = he->stat.period; 16714135663SNamhyung Kim u64 total_period = hists__total_period(he->hists); 16814135663SNamhyung Kim 16914135663SNamhyung Kim if (unlikely(total_period == 0)) 17014135663SNamhyung Kim return 0; 17114135663SNamhyung Kim 17214135663SNamhyung Kim if (symbol_conf.cumulate_callchain) 17314135663SNamhyung Kim period = he->stat_acc->period; 17414135663SNamhyung Kim 17514135663SNamhyung Kim return period * 100.0 / total_period; 17614135663SNamhyung Kim } 17714135663SNamhyung Kim 178e95cf700SJiri Olsa static inline u64 cl_address(u64 address) 179e95cf700SJiri Olsa { 180e95cf700SJiri Olsa /* return the cacheline of the address */ 181e95cf700SJiri Olsa return (address & ~(cacheline_size - 1)); 182e95cf700SJiri Olsa } 18314135663SNamhyung Kim 184d3927110SJiri Olsa static inline u64 cl_offset(u64 address) 185d3927110SJiri Olsa { 186d3927110SJiri Olsa /* return the cacheline of the address */ 187d3927110SJiri Olsa return (address & (cacheline_size - 1)); 188d3927110SJiri Olsa } 189d3927110SJiri Olsa 19055369fc1SNamhyung Kim enum sort_mode { 19155369fc1SNamhyung Kim SORT_MODE__NORMAL, 19255369fc1SNamhyung Kim SORT_MODE__BRANCH, 19355369fc1SNamhyung Kim SORT_MODE__MEMORY, 194512ae1bdSNamhyung Kim SORT_MODE__TOP, 195512ae1bdSNamhyung Kim SORT_MODE__DIFF, 196d49dadeaSNamhyung Kim SORT_MODE__TRACEPOINT, 19755369fc1SNamhyung Kim }; 19855369fc1SNamhyung Kim 199a4fb581bSFrederic Weisbecker enum sort_type { 200fc5871edSNamhyung Kim /* common sort keys */ 201a4fb581bSFrederic Weisbecker SORT_PID, 202a4fb581bSFrederic Weisbecker SORT_COMM, 203a4fb581bSFrederic Weisbecker SORT_DSO, 204a4fb581bSFrederic Weisbecker SORT_SYM, 205f60f3593SArun Sharma SORT_PARENT, 206f60f3593SArun Sharma SORT_CPU, 2072e7ea3abSKan Liang SORT_SOCKET, 208fc5871edSNamhyung Kim SORT_SRCLINE, 20931191a85SAndi Kleen SORT_SRCFILE, 210f9ea55d0SAndi Kleen SORT_LOCAL_WEIGHT, 211f9ea55d0SAndi Kleen SORT_GLOBAL_WEIGHT, 212475eeab9SAndi Kleen SORT_TRANSACTION, 213a34bb6a0SNamhyung Kim SORT_TRACE, 214fc5871edSNamhyung Kim 215fc5871edSNamhyung Kim /* branch stack specific sort keys */ 216fc5871edSNamhyung Kim __SORT_BRANCH_STACK, 217fc5871edSNamhyung Kim SORT_DSO_FROM = __SORT_BRANCH_STACK, 218b5387528SRoberto Agostino Vitillo SORT_DSO_TO, 219b5387528SRoberto Agostino Vitillo SORT_SYM_FROM, 220b5387528SRoberto Agostino Vitillo SORT_SYM_TO, 221b5387528SRoberto Agostino Vitillo SORT_MISPREDICT, 222f5d05bceSAndi Kleen SORT_ABORT, 223f5d05bceSAndi Kleen SORT_IN_TX, 2240e332f03SAndi Kleen SORT_CYCLES, 225afab87b9SNamhyung Kim 226afab87b9SNamhyung Kim /* memory mode specific sort keys */ 227afab87b9SNamhyung Kim __SORT_MEMORY_MODE, 228f9ea55d0SAndi Kleen SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE, 229afab87b9SNamhyung Kim SORT_MEM_DADDR_DSO, 230afab87b9SNamhyung Kim SORT_MEM_LOCKED, 231afab87b9SNamhyung Kim SORT_MEM_TLB, 232afab87b9SNamhyung Kim SORT_MEM_LVL, 233afab87b9SNamhyung Kim SORT_MEM_SNOOP, 2349b32ba71SDon Zickus SORT_MEM_DCACHELINE, 23528e6db20SDon Zickus SORT_MEM_IADDR_SYMBOL, 236a4fb581bSFrederic Weisbecker }; 237a4fb581bSFrederic Weisbecker 238dd68ada2SJohn Kacur /* 239dd68ada2SJohn Kacur * configurable sorting bits 240dd68ada2SJohn Kacur */ 241dd68ada2SJohn Kacur 242dd68ada2SJohn Kacur struct sort_entry { 243fcd14984SFrederic Weisbecker const char *se_header; 244dd68ada2SJohn Kacur 245fcd14984SFrederic Weisbecker int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); 246fcd14984SFrederic Weisbecker int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *); 247202e7a6dSNamhyung Kim int64_t (*se_sort)(struct hist_entry *, struct hist_entry *); 248316c7136SArnaldo Carvalho de Melo int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size, 249a4e3b956SArnaldo Carvalho de Melo unsigned int width); 25054430101SNamhyung Kim int (*se_filter)(struct hist_entry *he, int type, const void *arg); 2518a6c5b26SArnaldo Carvalho de Melo u8 se_width_idx; 252dd68ada2SJohn Kacur }; 253dd68ada2SJohn Kacur 254dd68ada2SJohn Kacur extern struct sort_entry sort_thread; 255dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list; 256dd68ada2SJohn Kacur 25740184c46SNamhyung Kim struct perf_evlist; 25840184c46SNamhyung Kim struct pevent; 25940184c46SNamhyung Kim int setup_sorting(struct perf_evlist *evlist); 260a7d945bcSNamhyung Kim int setup_output_field(void); 2611c89fe9bSNamhyung Kim void reset_output_field(void); 26208e71542SNamhyung Kim void sort__setup_elide(FILE *fp); 263f2998422SJiri Olsa void perf_hpp__set_elide(int idx, bool elide); 264dd68ada2SJohn Kacur 265b21484f1SGreg Price int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); 266b21484f1SGreg Price 2672f3f9bcfSJiri Olsa bool is_strict_order(const char *order); 268beeaaeb3SJiri Olsa 269beeaaeb3SJiri Olsa int hpp_dimension__add_output(unsigned col); 270dd68ada2SJohn Kacur #endif /* __PERF_SORT_H */ 271