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 #include "sort.h" 26dd68ada2SJohn Kacur 27dd68ada2SJohn Kacur extern regex_t parent_regex; 28edb7c60eSArnaldo Carvalho de Melo extern const char *sort_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; 8559fd5306SArnaldo Carvalho de Melo struct map_symbol ms; 86a5e29acaSArnaldo Carvalho de Melo struct thread *thread; 87dd68ada2SJohn Kacur u64 ip; 88f60f3593SArun Sharma s32 cpu; 890f0cbf7aSArnaldo Carvalho de Melo 9096c47f19SJiri Olsa struct hist_entry_diff diff; 9196c47f19SJiri Olsa 92e0af43d2SJiri Olsa /* We are added by hists__add_dummy_entry. */ 93e0af43d2SJiri Olsa bool dummy; 94e0af43d2SJiri Olsa 950f0cbf7aSArnaldo Carvalho de Melo /* XXX These two should move to some tree widget lib */ 960f0cbf7aSArnaldo Carvalho de Melo u16 row_offset; 970f0cbf7aSArnaldo Carvalho de Melo u16 nr_rows; 980f0cbf7aSArnaldo Carvalho de Melo 990f0cbf7aSArnaldo Carvalho de Melo bool init_have_children; 100dd68ada2SJohn Kacur char level; 101df71d95fSArnaldo Carvalho de Melo bool used; 102a5e29acaSArnaldo Carvalho de Melo u8 filtered; 103409a8be6SArnaldo Carvalho de Melo char *srcline; 104439d473bSArnaldo Carvalho de Melo struct symbol *parent; 10586a9eee0SArnaldo Carvalho de Melo unsigned long position; 106dd68ada2SJohn Kacur struct rb_root sorted_chain; 107b5387528SRoberto Agostino Vitillo struct branch_info *branch_info; 108ae359f19SJiri Olsa struct hists *hists; 10998a3b32cSStephane Eranian struct mem_info *mem_info; 11098a3b32cSStephane Eranian struct callchain_root callchain[0]; /* must be last member */ 11186a9eee0SArnaldo Carvalho de Melo }; 112dd68ada2SJohn Kacur 113b821c732SArnaldo Carvalho de Melo static inline bool hist_entry__has_pairs(struct hist_entry *he) 114b821c732SArnaldo Carvalho de Melo { 115b821c732SArnaldo Carvalho de Melo return !list_empty(&he->pairs.node); 116b821c732SArnaldo Carvalho de Melo } 117b821c732SArnaldo Carvalho de Melo 118b821c732SArnaldo Carvalho de Melo static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he) 119b821c732SArnaldo Carvalho de Melo { 120b821c732SArnaldo Carvalho de Melo if (hist_entry__has_pairs(he)) 121b821c732SArnaldo Carvalho de Melo return list_entry(he->pairs.node.next, struct hist_entry, pairs.node); 122b821c732SArnaldo Carvalho de Melo return NULL; 123b821c732SArnaldo Carvalho de Melo } 124b821c732SArnaldo Carvalho de Melo 1254d23322aSJiri Olsa static inline void hist_entry__add_pair(struct hist_entry *pair, 1264d23322aSJiri Olsa struct hist_entry *he) 127b821c732SArnaldo Carvalho de Melo { 1284d23322aSJiri Olsa list_add_tail(&pair->pairs.node, &he->pairs.head); 129b821c732SArnaldo Carvalho de Melo } 130b821c732SArnaldo Carvalho de Melo 13155369fc1SNamhyung Kim enum sort_mode { 13255369fc1SNamhyung Kim SORT_MODE__NORMAL, 13355369fc1SNamhyung Kim SORT_MODE__BRANCH, 13455369fc1SNamhyung Kim SORT_MODE__MEMORY, 13555369fc1SNamhyung Kim }; 13655369fc1SNamhyung Kim 137a4fb581bSFrederic Weisbecker enum sort_type { 138fc5871edSNamhyung Kim /* common sort keys */ 139a4fb581bSFrederic Weisbecker SORT_PID, 140a4fb581bSFrederic Weisbecker SORT_COMM, 141a4fb581bSFrederic Weisbecker SORT_DSO, 142a4fb581bSFrederic Weisbecker SORT_SYM, 143f60f3593SArun Sharma SORT_PARENT, 144f60f3593SArun Sharma SORT_CPU, 145fc5871edSNamhyung Kim SORT_SRCLINE, 146f9ea55d0SAndi Kleen SORT_LOCAL_WEIGHT, 147f9ea55d0SAndi Kleen SORT_GLOBAL_WEIGHT, 148fc5871edSNamhyung Kim 149fc5871edSNamhyung Kim /* branch stack specific sort keys */ 150fc5871edSNamhyung Kim __SORT_BRANCH_STACK, 151fc5871edSNamhyung Kim SORT_DSO_FROM = __SORT_BRANCH_STACK, 152b5387528SRoberto Agostino Vitillo SORT_DSO_TO, 153b5387528SRoberto Agostino Vitillo SORT_SYM_FROM, 154b5387528SRoberto Agostino Vitillo SORT_SYM_TO, 155b5387528SRoberto Agostino Vitillo SORT_MISPREDICT, 156f5d05bceSAndi Kleen SORT_ABORT, 157f5d05bceSAndi Kleen SORT_IN_TX, 158afab87b9SNamhyung Kim 159afab87b9SNamhyung Kim /* memory mode specific sort keys */ 160afab87b9SNamhyung Kim __SORT_MEMORY_MODE, 161f9ea55d0SAndi Kleen SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE, 162afab87b9SNamhyung Kim SORT_MEM_DADDR_DSO, 163afab87b9SNamhyung Kim SORT_MEM_LOCKED, 164afab87b9SNamhyung Kim SORT_MEM_TLB, 165afab87b9SNamhyung Kim SORT_MEM_LVL, 166afab87b9SNamhyung Kim SORT_MEM_SNOOP, 167a4fb581bSFrederic Weisbecker }; 168a4fb581bSFrederic Weisbecker 169dd68ada2SJohn Kacur /* 170dd68ada2SJohn Kacur * configurable sorting bits 171dd68ada2SJohn Kacur */ 172dd68ada2SJohn Kacur 173dd68ada2SJohn Kacur struct sort_entry { 174dd68ada2SJohn Kacur struct list_head list; 175dd68ada2SJohn Kacur 176fcd14984SFrederic Weisbecker const char *se_header; 177dd68ada2SJohn Kacur 178fcd14984SFrederic Weisbecker int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); 179fcd14984SFrederic Weisbecker int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *); 180fcd14984SFrederic Weisbecker int (*se_snprintf)(struct hist_entry *self, char *bf, size_t size, 181a4e3b956SArnaldo Carvalho de Melo unsigned int width); 1828a6c5b26SArnaldo Carvalho de Melo u8 se_width_idx; 183dd68ada2SJohn Kacur bool elide; 184dd68ada2SJohn Kacur }; 185dd68ada2SJohn Kacur 186dd68ada2SJohn Kacur extern struct sort_entry sort_thread; 187dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list; 188dd68ada2SJohn Kacur 18955309985SNamhyung Kim int setup_sorting(void); 190dd68ada2SJohn Kacur extern int sort_dimension__add(const char *); 19108e71542SNamhyung Kim void sort__setup_elide(FILE *fp); 192dd68ada2SJohn Kacur 193b21484f1SGreg Price int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset); 194b21484f1SGreg Price 195dd68ada2SJohn Kacur #endif /* __PERF_SORT_H */ 196