xref: /openbmc/linux/tools/perf/util/sort.h (revision b21484f1)
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 
920f0cbf7aSArnaldo Carvalho de Melo 	/* XXX These two should move to some tree widget lib */
930f0cbf7aSArnaldo Carvalho de Melo 	u16			row_offset;
940f0cbf7aSArnaldo Carvalho de Melo 	u16			nr_rows;
950f0cbf7aSArnaldo Carvalho de Melo 
960f0cbf7aSArnaldo Carvalho de Melo 	bool			init_have_children;
97dd68ada2SJohn Kacur 	char			level;
98df71d95fSArnaldo Carvalho de Melo 	bool			used;
99a5e29acaSArnaldo Carvalho de Melo 	u8			filtered;
100409a8be6SArnaldo Carvalho de Melo 	char			*srcline;
101439d473bSArnaldo Carvalho de Melo 	struct symbol		*parent;
10286a9eee0SArnaldo Carvalho de Melo 	unsigned long		position;
103dd68ada2SJohn Kacur 	struct rb_root		sorted_chain;
104b5387528SRoberto Agostino Vitillo 	struct branch_info	*branch_info;
105ae359f19SJiri Olsa 	struct hists		*hists;
10698a3b32cSStephane Eranian 	struct mem_info		*mem_info;
10798a3b32cSStephane Eranian 	struct callchain_root	callchain[0]; /* must be last member */
10886a9eee0SArnaldo Carvalho de Melo };
109dd68ada2SJohn Kacur 
110b821c732SArnaldo Carvalho de Melo static inline bool hist_entry__has_pairs(struct hist_entry *he)
111b821c732SArnaldo Carvalho de Melo {
112b821c732SArnaldo Carvalho de Melo 	return !list_empty(&he->pairs.node);
113b821c732SArnaldo Carvalho de Melo }
114b821c732SArnaldo Carvalho de Melo 
115b821c732SArnaldo Carvalho de Melo static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
116b821c732SArnaldo Carvalho de Melo {
117b821c732SArnaldo Carvalho de Melo 	if (hist_entry__has_pairs(he))
118b821c732SArnaldo Carvalho de Melo 		return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
119b821c732SArnaldo Carvalho de Melo 	return NULL;
120b821c732SArnaldo Carvalho de Melo }
121b821c732SArnaldo Carvalho de Melo 
1224d23322aSJiri Olsa static inline void hist_entry__add_pair(struct hist_entry *pair,
1234d23322aSJiri Olsa 					struct hist_entry *he)
124b821c732SArnaldo Carvalho de Melo {
1254d23322aSJiri Olsa 	list_add_tail(&pair->pairs.node, &he->pairs.head);
126b821c732SArnaldo Carvalho de Melo }
127b821c732SArnaldo Carvalho de Melo 
12855369fc1SNamhyung Kim enum sort_mode {
12955369fc1SNamhyung Kim 	SORT_MODE__NORMAL,
13055369fc1SNamhyung Kim 	SORT_MODE__BRANCH,
13155369fc1SNamhyung Kim 	SORT_MODE__MEMORY,
13255369fc1SNamhyung Kim };
13355369fc1SNamhyung Kim 
134a4fb581bSFrederic Weisbecker enum sort_type {
135fc5871edSNamhyung Kim 	/* common sort keys */
136a4fb581bSFrederic Weisbecker 	SORT_PID,
137a4fb581bSFrederic Weisbecker 	SORT_COMM,
138a4fb581bSFrederic Weisbecker 	SORT_DSO,
139a4fb581bSFrederic Weisbecker 	SORT_SYM,
140f60f3593SArun Sharma 	SORT_PARENT,
141f60f3593SArun Sharma 	SORT_CPU,
142fc5871edSNamhyung Kim 	SORT_SRCLINE,
143fc5871edSNamhyung Kim 
144fc5871edSNamhyung Kim 	/* branch stack specific sort keys */
145fc5871edSNamhyung Kim 	__SORT_BRANCH_STACK,
146fc5871edSNamhyung Kim 	SORT_DSO_FROM = __SORT_BRANCH_STACK,
147b5387528SRoberto Agostino Vitillo 	SORT_DSO_TO,
148b5387528SRoberto Agostino Vitillo 	SORT_SYM_FROM,
149b5387528SRoberto Agostino Vitillo 	SORT_SYM_TO,
150b5387528SRoberto Agostino Vitillo 	SORT_MISPREDICT,
151afab87b9SNamhyung Kim 
152afab87b9SNamhyung Kim 	/* memory mode specific sort keys */
153afab87b9SNamhyung Kim 	__SORT_MEMORY_MODE,
154afab87b9SNamhyung Kim 	SORT_LOCAL_WEIGHT = __SORT_MEMORY_MODE,
155afab87b9SNamhyung Kim 	SORT_GLOBAL_WEIGHT,
156afab87b9SNamhyung Kim 	SORT_MEM_DADDR_SYMBOL,
157afab87b9SNamhyung Kim 	SORT_MEM_DADDR_DSO,
158afab87b9SNamhyung Kim 	SORT_MEM_LOCKED,
159afab87b9SNamhyung Kim 	SORT_MEM_TLB,
160afab87b9SNamhyung Kim 	SORT_MEM_LVL,
161afab87b9SNamhyung Kim 	SORT_MEM_SNOOP,
162a4fb581bSFrederic Weisbecker };
163a4fb581bSFrederic Weisbecker 
164dd68ada2SJohn Kacur /*
165dd68ada2SJohn Kacur  * configurable sorting bits
166dd68ada2SJohn Kacur  */
167dd68ada2SJohn Kacur 
168dd68ada2SJohn Kacur struct sort_entry {
169dd68ada2SJohn Kacur 	struct list_head list;
170dd68ada2SJohn Kacur 
171fcd14984SFrederic Weisbecker 	const char *se_header;
172dd68ada2SJohn Kacur 
173fcd14984SFrederic Weisbecker 	int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
174fcd14984SFrederic Weisbecker 	int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
175fcd14984SFrederic Weisbecker 	int	(*se_snprintf)(struct hist_entry *self, char *bf, size_t size,
176a4e3b956SArnaldo Carvalho de Melo 			       unsigned int width);
1778a6c5b26SArnaldo Carvalho de Melo 	u8	se_width_idx;
178dd68ada2SJohn Kacur 	bool	elide;
179dd68ada2SJohn Kacur };
180dd68ada2SJohn Kacur 
181dd68ada2SJohn Kacur extern struct sort_entry sort_thread;
182dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list;
183dd68ada2SJohn Kacur 
18455309985SNamhyung Kim int setup_sorting(void);
185dd68ada2SJohn Kacur extern int sort_dimension__add(const char *);
18608e71542SNamhyung Kim void sort__setup_elide(FILE *fp);
187dd68ada2SJohn Kacur 
188b21484f1SGreg Price int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
189b21484f1SGreg Price 
190dd68ada2SJohn Kacur #endif	/* __PERF_SORT_H */
191