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 21dd68ada2SJohn Kacur #include "parse-options.h" 22dd68ada2SJohn Kacur #include "parse-events.h" 23dd68ada2SJohn Kacur 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; 35dd68ada2SJohn Kacur extern int sort__has_parent; 361af55640SNamhyung Kim extern int sort__has_sym; 3755369fc1SNamhyung Kim extern enum sort_mode sort__mode; 38dd68ada2SJohn Kacur extern struct sort_entry sort_comm; 39dd68ada2SJohn Kacur extern struct sort_entry sort_dso; 40dd68ada2SJohn Kacur extern struct sort_entry sort_sym; 41dd68ada2SJohn Kacur extern struct sort_entry sort_parent; 42a68c2c58SStephane Eranian extern struct sort_entry sort_dso_from; 43a68c2c58SStephane Eranian extern struct sort_entry sort_dso_to; 44a68c2c58SStephane Eranian extern struct sort_entry sort_sym_from; 45a68c2c58SStephane Eranian extern struct sort_entry sort_sym_to; 46a4fb581bSFrederic Weisbecker extern enum sort_type sort__first_dimension; 47dd68ada2SJohn Kacur 48b24c28f7SNamhyung Kim struct he_stat { 49b24c28f7SNamhyung Kim u64 period; 50b24c28f7SNamhyung Kim u64 period_sys; 51b24c28f7SNamhyung Kim u64 period_us; 52b24c28f7SNamhyung Kim u64 period_guest_sys; 53b24c28f7SNamhyung Kim u64 period_guest_us; 5405484298SAndi Kleen u64 weight; 55b24c28f7SNamhyung Kim u32 nr_events; 56b24c28f7SNamhyung Kim }; 57b24c28f7SNamhyung Kim 5896c47f19SJiri Olsa struct hist_entry_diff { 5996c47f19SJiri Olsa bool computed; 6096c47f19SJiri Olsa 6196c47f19SJiri Olsa /* PERF_HPP__DELTA */ 6296c47f19SJiri Olsa double period_ratio_delta; 6396c47f19SJiri Olsa 6496c47f19SJiri Olsa /* PERF_HPP__RATIO */ 6596c47f19SJiri Olsa double period_ratio; 6681d5f958SJiri Olsa 6781d5f958SJiri Olsa /* HISTC_WEIGHTED_DIFF */ 6881d5f958SJiri Olsa s64 wdiff; 6996c47f19SJiri Olsa }; 7096c47f19SJiri Olsa 710f0cbf7aSArnaldo Carvalho de Melo /** 720f0cbf7aSArnaldo Carvalho de Melo * struct hist_entry - histogram entry 730f0cbf7aSArnaldo Carvalho de Melo * 740f0cbf7aSArnaldo Carvalho de Melo * @row_offset - offset from the first callchain expanded to appear on screen 750f0cbf7aSArnaldo Carvalho de Melo * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding 760f0cbf7aSArnaldo Carvalho de Melo */ 77dd68ada2SJohn Kacur struct hist_entry { 781980c2ebSArnaldo Carvalho de Melo struct rb_node rb_node_in; 79dd68ada2SJohn Kacur struct rb_node rb_node; 80b821c732SArnaldo Carvalho de Melo union { 81b821c732SArnaldo Carvalho de Melo struct list_head node; 82b821c732SArnaldo Carvalho de Melo struct list_head head; 83b821c732SArnaldo Carvalho de Melo } pairs; 84b24c28f7SNamhyung Kim struct he_stat stat; 85f8be1c8cSNamhyung Kim struct he_stat *stat_acc; 8659fd5306SArnaldo Carvalho de Melo struct map_symbol ms; 87a5e29acaSArnaldo Carvalho de Melo struct thread *thread; 884dfced35SNamhyung Kim struct comm *comm; 89dd68ada2SJohn Kacur u64 ip; 90475eeab9SAndi Kleen u64 transaction; 91f60f3593SArun Sharma s32 cpu; 920f0cbf7aSArnaldo Carvalho de Melo 9396c47f19SJiri Olsa struct hist_entry_diff diff; 9496c47f19SJiri Olsa 95e0af43d2SJiri Olsa /* We are added by hists__add_dummy_entry. */ 96e0af43d2SJiri Olsa bool dummy; 97e0af43d2SJiri Olsa 980f0cbf7aSArnaldo Carvalho de Melo /* XXX These two should move to some tree widget lib */ 990f0cbf7aSArnaldo Carvalho de Melo u16 row_offset; 1000f0cbf7aSArnaldo Carvalho de Melo u16 nr_rows; 1010f0cbf7aSArnaldo Carvalho de Melo 1020f0cbf7aSArnaldo Carvalho de Melo bool init_have_children; 103dd68ada2SJohn Kacur char level; 104df71d95fSArnaldo Carvalho de Melo bool used; 105a5e29acaSArnaldo Carvalho de Melo u8 filtered; 106409a8be6SArnaldo Carvalho de Melo char *srcline; 107439d473bSArnaldo Carvalho de Melo struct symbol *parent; 10886a9eee0SArnaldo Carvalho de Melo unsigned long position; 109dd68ada2SJohn Kacur struct rb_root sorted_chain; 110b5387528SRoberto Agostino Vitillo struct branch_info *branch_info; 111ae359f19SJiri Olsa struct hists *hists; 11298a3b32cSStephane Eranian struct mem_info *mem_info; 11398a3b32cSStephane Eranian struct callchain_root callchain[0]; /* must be last member */ 11486a9eee0SArnaldo Carvalho de Melo }; 115dd68ada2SJohn Kacur 116b821c732SArnaldo Carvalho de Melo static inline bool hist_entry__has_pairs(struct hist_entry *he) 117b821c732SArnaldo Carvalho de Melo { 118b821c732SArnaldo Carvalho de Melo return !list_empty(&he->pairs.node); 119b821c732SArnaldo Carvalho de Melo } 120b821c732SArnaldo Carvalho de Melo 121b821c732SArnaldo Carvalho de Melo static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he) 122b821c732SArnaldo Carvalho de Melo { 123b821c732SArnaldo Carvalho de Melo if (hist_entry__has_pairs(he)) 124b821c732SArnaldo Carvalho de Melo return list_entry(he->pairs.node.next, struct hist_entry, pairs.node); 125b821c732SArnaldo Carvalho de Melo return NULL; 126b821c732SArnaldo Carvalho de Melo } 127b821c732SArnaldo Carvalho de Melo 1284d23322aSJiri Olsa static inline void hist_entry__add_pair(struct hist_entry *pair, 1294d23322aSJiri Olsa struct hist_entry *he) 130b821c732SArnaldo Carvalho de Melo { 1314d23322aSJiri Olsa list_add_tail(&pair->pairs.node, &he->pairs.head); 132b821c732SArnaldo Carvalho de Melo } 133b821c732SArnaldo Carvalho de Melo 13455369fc1SNamhyung Kim enum sort_mode { 13555369fc1SNamhyung Kim SORT_MODE__NORMAL, 13655369fc1SNamhyung Kim SORT_MODE__BRANCH, 13755369fc1SNamhyung Kim SORT_MODE__MEMORY, 138512ae1bdSNamhyung Kim SORT_MODE__TOP, 139512ae1bdSNamhyung Kim SORT_MODE__DIFF, 14055369fc1SNamhyung Kim }; 14155369fc1SNamhyung Kim 142a4fb581bSFrederic Weisbecker enum sort_type { 143fc5871edSNamhyung Kim /* common sort keys */ 144a4fb581bSFrederic Weisbecker SORT_PID, 145a4fb581bSFrederic Weisbecker SORT_COMM, 146a4fb581bSFrederic Weisbecker SORT_DSO, 147a4fb581bSFrederic Weisbecker SORT_SYM, 148f60f3593SArun Sharma SORT_PARENT, 149f60f3593SArun Sharma SORT_CPU, 150fc5871edSNamhyung Kim SORT_SRCLINE, 151f9ea55d0SAndi Kleen SORT_LOCAL_WEIGHT, 152f9ea55d0SAndi Kleen SORT_GLOBAL_WEIGHT, 153475eeab9SAndi Kleen SORT_TRANSACTION, 154fc5871edSNamhyung Kim 155fc5871edSNamhyung Kim /* branch stack specific sort keys */ 156fc5871edSNamhyung Kim __SORT_BRANCH_STACK, 157fc5871edSNamhyung Kim SORT_DSO_FROM = __SORT_BRANCH_STACK, 158b5387528SRoberto Agostino Vitillo SORT_DSO_TO, 159b5387528SRoberto Agostino Vitillo SORT_SYM_FROM, 160b5387528SRoberto Agostino Vitillo SORT_SYM_TO, 161b5387528SRoberto Agostino Vitillo SORT_MISPREDICT, 162f5d05bceSAndi Kleen SORT_ABORT, 163f5d05bceSAndi Kleen SORT_IN_TX, 164afab87b9SNamhyung Kim 165afab87b9SNamhyung Kim /* memory mode specific sort keys */ 166afab87b9SNamhyung Kim __SORT_MEMORY_MODE, 167f9ea55d0SAndi Kleen SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE, 168afab87b9SNamhyung Kim SORT_MEM_DADDR_DSO, 169afab87b9SNamhyung Kim SORT_MEM_LOCKED, 170afab87b9SNamhyung Kim SORT_MEM_TLB, 171afab87b9SNamhyung Kim SORT_MEM_LVL, 172afab87b9SNamhyung Kim SORT_MEM_SNOOP, 173a4fb581bSFrederic Weisbecker }; 174a4fb581bSFrederic Weisbecker 175dd68ada2SJohn Kacur /* 176dd68ada2SJohn Kacur * configurable sorting bits 177dd68ada2SJohn Kacur */ 178dd68ada2SJohn Kacur 179dd68ada2SJohn Kacur struct sort_entry { 180dd68ada2SJohn Kacur struct list_head list; 181dd68ada2SJohn Kacur 182fcd14984SFrederic Weisbecker const char *se_header; 183dd68ada2SJohn Kacur 184fcd14984SFrederic Weisbecker int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); 185fcd14984SFrederic Weisbecker int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *); 186202e7a6dSNamhyung Kim int64_t (*se_sort)(struct hist_entry *, struct hist_entry *); 187316c7136SArnaldo Carvalho de Melo int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size, 188a4e3b956SArnaldo Carvalho de Melo unsigned int width); 1898a6c5b26SArnaldo Carvalho de Melo u8 se_width_idx; 190dd68ada2SJohn Kacur bool elide; 191dd68ada2SJohn Kacur }; 192dd68ada2SJohn Kacur 193dd68ada2SJohn Kacur extern struct sort_entry sort_thread; 194dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list; 195dd68ada2SJohn Kacur 19655309985SNamhyung Kim int setup_sorting(void); 197a7d945bcSNamhyung Kim int setup_output_field(void); 1981c89fe9bSNamhyung Kim void reset_output_field(void); 199dd68ada2SJohn Kacur extern int sort_dimension__add(const char *); 20008e71542SNamhyung Kim void sort__setup_elide(FILE *fp); 201dd68ada2SJohn Kacur 202b21484f1SGreg Price int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); 203b21484f1SGreg Price 204dd68ada2SJohn Kacur #endif /* __PERF_SORT_H */ 205