xref: /openbmc/linux/tools/perf/util/sort.h (revision a7d945bc)
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;
8559fd5306SArnaldo Carvalho de Melo 	struct map_symbol	ms;
86a5e29acaSArnaldo Carvalho de Melo 	struct thread		*thread;
874dfced35SNamhyung Kim 	struct comm		*comm;
88dd68ada2SJohn Kacur 	u64			ip;
89475eeab9SAndi Kleen 	u64			transaction;
90f60f3593SArun Sharma 	s32			cpu;
910f0cbf7aSArnaldo Carvalho de Melo 
9296c47f19SJiri Olsa 	struct hist_entry_diff	diff;
9396c47f19SJiri Olsa 
94e0af43d2SJiri Olsa 	/* We are added by hists__add_dummy_entry. */
95e0af43d2SJiri Olsa 	bool			dummy;
96e0af43d2SJiri Olsa 
970f0cbf7aSArnaldo Carvalho de Melo 	/* XXX These two should move to some tree widget lib */
980f0cbf7aSArnaldo Carvalho de Melo 	u16			row_offset;
990f0cbf7aSArnaldo Carvalho de Melo 	u16			nr_rows;
1000f0cbf7aSArnaldo Carvalho de Melo 
1010f0cbf7aSArnaldo Carvalho de Melo 	bool			init_have_children;
102dd68ada2SJohn Kacur 	char			level;
103df71d95fSArnaldo Carvalho de Melo 	bool			used;
104a5e29acaSArnaldo Carvalho de Melo 	u8			filtered;
105409a8be6SArnaldo Carvalho de Melo 	char			*srcline;
106439d473bSArnaldo Carvalho de Melo 	struct symbol		*parent;
10786a9eee0SArnaldo Carvalho de Melo 	unsigned long		position;
108dd68ada2SJohn Kacur 	struct rb_root		sorted_chain;
109b5387528SRoberto Agostino Vitillo 	struct branch_info	*branch_info;
110ae359f19SJiri Olsa 	struct hists		*hists;
11198a3b32cSStephane Eranian 	struct mem_info		*mem_info;
11298a3b32cSStephane Eranian 	struct callchain_root	callchain[0]; /* must be last member */
11386a9eee0SArnaldo Carvalho de Melo };
114dd68ada2SJohn Kacur 
115b821c732SArnaldo Carvalho de Melo static inline bool hist_entry__has_pairs(struct hist_entry *he)
116b821c732SArnaldo Carvalho de Melo {
117b821c732SArnaldo Carvalho de Melo 	return !list_empty(&he->pairs.node);
118b821c732SArnaldo Carvalho de Melo }
119b821c732SArnaldo Carvalho de Melo 
120b821c732SArnaldo Carvalho de Melo static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
121b821c732SArnaldo Carvalho de Melo {
122b821c732SArnaldo Carvalho de Melo 	if (hist_entry__has_pairs(he))
123b821c732SArnaldo Carvalho de Melo 		return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
124b821c732SArnaldo Carvalho de Melo 	return NULL;
125b821c732SArnaldo Carvalho de Melo }
126b821c732SArnaldo Carvalho de Melo 
1274d23322aSJiri Olsa static inline void hist_entry__add_pair(struct hist_entry *pair,
1284d23322aSJiri Olsa 					struct hist_entry *he)
129b821c732SArnaldo Carvalho de Melo {
1304d23322aSJiri Olsa 	list_add_tail(&pair->pairs.node, &he->pairs.head);
131b821c732SArnaldo Carvalho de Melo }
132b821c732SArnaldo Carvalho de Melo 
13355369fc1SNamhyung Kim enum sort_mode {
13455369fc1SNamhyung Kim 	SORT_MODE__NORMAL,
13555369fc1SNamhyung Kim 	SORT_MODE__BRANCH,
13655369fc1SNamhyung Kim 	SORT_MODE__MEMORY,
137512ae1bdSNamhyung Kim 	SORT_MODE__TOP,
138512ae1bdSNamhyung Kim 	SORT_MODE__DIFF,
13955369fc1SNamhyung Kim };
14055369fc1SNamhyung Kim 
141a4fb581bSFrederic Weisbecker enum sort_type {
142fc5871edSNamhyung Kim 	/* common sort keys */
143a4fb581bSFrederic Weisbecker 	SORT_PID,
144a4fb581bSFrederic Weisbecker 	SORT_COMM,
145a4fb581bSFrederic Weisbecker 	SORT_DSO,
146a4fb581bSFrederic Weisbecker 	SORT_SYM,
147f60f3593SArun Sharma 	SORT_PARENT,
148f60f3593SArun Sharma 	SORT_CPU,
149fc5871edSNamhyung Kim 	SORT_SRCLINE,
150f9ea55d0SAndi Kleen 	SORT_LOCAL_WEIGHT,
151f9ea55d0SAndi Kleen 	SORT_GLOBAL_WEIGHT,
152475eeab9SAndi Kleen 	SORT_TRANSACTION,
153fc5871edSNamhyung Kim 
154fc5871edSNamhyung Kim 	/* branch stack specific sort keys */
155fc5871edSNamhyung Kim 	__SORT_BRANCH_STACK,
156fc5871edSNamhyung Kim 	SORT_DSO_FROM = __SORT_BRANCH_STACK,
157b5387528SRoberto Agostino Vitillo 	SORT_DSO_TO,
158b5387528SRoberto Agostino Vitillo 	SORT_SYM_FROM,
159b5387528SRoberto Agostino Vitillo 	SORT_SYM_TO,
160b5387528SRoberto Agostino Vitillo 	SORT_MISPREDICT,
161f5d05bceSAndi Kleen 	SORT_ABORT,
162f5d05bceSAndi Kleen 	SORT_IN_TX,
163afab87b9SNamhyung Kim 
164afab87b9SNamhyung Kim 	/* memory mode specific sort keys */
165afab87b9SNamhyung Kim 	__SORT_MEMORY_MODE,
166f9ea55d0SAndi Kleen 	SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
167afab87b9SNamhyung Kim 	SORT_MEM_DADDR_DSO,
168afab87b9SNamhyung Kim 	SORT_MEM_LOCKED,
169afab87b9SNamhyung Kim 	SORT_MEM_TLB,
170afab87b9SNamhyung Kim 	SORT_MEM_LVL,
171afab87b9SNamhyung Kim 	SORT_MEM_SNOOP,
172a4fb581bSFrederic Weisbecker };
173a4fb581bSFrederic Weisbecker 
174dd68ada2SJohn Kacur /*
175dd68ada2SJohn Kacur  * configurable sorting bits
176dd68ada2SJohn Kacur  */
177dd68ada2SJohn Kacur 
178dd68ada2SJohn Kacur struct sort_entry {
179dd68ada2SJohn Kacur 	struct list_head list;
180dd68ada2SJohn Kacur 
181fcd14984SFrederic Weisbecker 	const char *se_header;
182dd68ada2SJohn Kacur 
183fcd14984SFrederic Weisbecker 	int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
184fcd14984SFrederic Weisbecker 	int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
185316c7136SArnaldo Carvalho de Melo 	int	(*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
186a4e3b956SArnaldo Carvalho de Melo 			       unsigned int width);
1878a6c5b26SArnaldo Carvalho de Melo 	u8	se_width_idx;
188dd68ada2SJohn Kacur 	bool	elide;
189dd68ada2SJohn Kacur };
190dd68ada2SJohn Kacur 
191dd68ada2SJohn Kacur extern struct sort_entry sort_thread;
192dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list;
193dd68ada2SJohn Kacur 
19455309985SNamhyung Kim int setup_sorting(void);
195a7d945bcSNamhyung Kim int setup_output_field(void);
196dd68ada2SJohn Kacur extern int sort_dimension__add(const char *);
19708e71542SNamhyung Kim void sort__setup_elide(FILE *fp);
198dd68ada2SJohn Kacur 
199b21484f1SGreg Price int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
200b21484f1SGreg Price 
201dd68ada2SJohn Kacur #endif	/* __PERF_SORT_H */
202