xref: /openbmc/linux/tools/perf/util/sort.h (revision dd464345)
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[];
32dd68ada2SJohn Kacur extern int sort__need_collapse;
33dd68ada2SJohn Kacur extern int sort__has_parent;
341af55640SNamhyung Kim extern int sort__has_sym;
35993ac88dSStephane Eranian extern int sort__branch_mode;
36dd68ada2SJohn Kacur extern struct sort_entry sort_comm;
37dd68ada2SJohn Kacur extern struct sort_entry sort_dso;
38dd68ada2SJohn Kacur extern struct sort_entry sort_sym;
39dd68ada2SJohn Kacur extern struct sort_entry sort_parent;
40a68c2c58SStephane Eranian extern struct sort_entry sort_dso_from;
41a68c2c58SStephane Eranian extern struct sort_entry sort_dso_to;
42a68c2c58SStephane Eranian extern struct sort_entry sort_sym_from;
43a68c2c58SStephane Eranian extern struct sort_entry sort_sym_to;
44a4fb581bSFrederic Weisbecker extern enum sort_type sort__first_dimension;
45dd68ada2SJohn Kacur 
460f0cbf7aSArnaldo Carvalho de Melo /**
470f0cbf7aSArnaldo Carvalho de Melo  * struct hist_entry - histogram entry
480f0cbf7aSArnaldo Carvalho de Melo  *
490f0cbf7aSArnaldo Carvalho de Melo  * @row_offset - offset from the first callchain expanded to appear on screen
500f0cbf7aSArnaldo Carvalho de Melo  * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
510f0cbf7aSArnaldo Carvalho de Melo  */
52dd68ada2SJohn Kacur struct hist_entry {
531980c2ebSArnaldo Carvalho de Melo 	struct rb_node		rb_node_in;
54dd68ada2SJohn Kacur 	struct rb_node		rb_node;
55c82ee828SArnaldo Carvalho de Melo 	u64			period;
56c82ee828SArnaldo Carvalho de Melo 	u64			period_sys;
57c82ee828SArnaldo Carvalho de Melo 	u64			period_us;
58c82ee828SArnaldo Carvalho de Melo 	u64			period_guest_sys;
59c82ee828SArnaldo Carvalho de Melo 	u64			period_guest_us;
6059fd5306SArnaldo Carvalho de Melo 	struct map_symbol	ms;
61a5e29acaSArnaldo Carvalho de Melo 	struct thread		*thread;
62dd68ada2SJohn Kacur 	u64			ip;
63f60f3593SArun Sharma 	s32			cpu;
64c82ee828SArnaldo Carvalho de Melo 	u32			nr_events;
650f0cbf7aSArnaldo Carvalho de Melo 
660f0cbf7aSArnaldo Carvalho de Melo 	/* XXX These two should move to some tree widget lib */
670f0cbf7aSArnaldo Carvalho de Melo 	u16			row_offset;
680f0cbf7aSArnaldo Carvalho de Melo 	u16			nr_rows;
690f0cbf7aSArnaldo Carvalho de Melo 
700f0cbf7aSArnaldo Carvalho de Melo 	bool			init_have_children;
71dd68ada2SJohn Kacur 	char			level;
72df71d95fSArnaldo Carvalho de Melo 	bool			used;
73a5e29acaSArnaldo Carvalho de Melo 	u8			filtered;
74409a8be6SArnaldo Carvalho de Melo 	char			*srcline;
75439d473bSArnaldo Carvalho de Melo 	struct symbol		*parent;
7686a9eee0SArnaldo Carvalho de Melo 	unsigned long		position;
77dd464345SJiri Olsa 	union {
7886a9eee0SArnaldo Carvalho de Melo 		struct hist_entry *pair;
79dd68ada2SJohn Kacur 		struct rb_root	  sorted_chain;
80dd68ada2SJohn Kacur 	};
81b5387528SRoberto Agostino Vitillo 	struct branch_info	*branch_info;
82ae359f19SJiri Olsa 	struct hists		*hists;
83d2009c51SFrederic Weisbecker 	struct callchain_root	callchain[0];
8486a9eee0SArnaldo Carvalho de Melo };
85dd68ada2SJohn Kacur 
86a4fb581bSFrederic Weisbecker enum sort_type {
87a4fb581bSFrederic Weisbecker 	SORT_PID,
88a4fb581bSFrederic Weisbecker 	SORT_COMM,
89a4fb581bSFrederic Weisbecker 	SORT_DSO,
90a4fb581bSFrederic Weisbecker 	SORT_SYM,
91f60f3593SArun Sharma 	SORT_PARENT,
92f60f3593SArun Sharma 	SORT_CPU,
93b5387528SRoberto Agostino Vitillo 	SORT_DSO_FROM,
94b5387528SRoberto Agostino Vitillo 	SORT_DSO_TO,
95b5387528SRoberto Agostino Vitillo 	SORT_SYM_FROM,
96b5387528SRoberto Agostino Vitillo 	SORT_SYM_TO,
97b5387528SRoberto Agostino Vitillo 	SORT_MISPREDICT,
98409a8be6SArnaldo Carvalho de Melo 	SORT_SRCLINE,
99a4fb581bSFrederic Weisbecker };
100a4fb581bSFrederic Weisbecker 
101dd68ada2SJohn Kacur /*
102dd68ada2SJohn Kacur  * configurable sorting bits
103dd68ada2SJohn Kacur  */
104dd68ada2SJohn Kacur 
105dd68ada2SJohn Kacur struct sort_entry {
106dd68ada2SJohn Kacur 	struct list_head list;
107dd68ada2SJohn Kacur 
108fcd14984SFrederic Weisbecker 	const char *se_header;
109dd68ada2SJohn Kacur 
110fcd14984SFrederic Weisbecker 	int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
111fcd14984SFrederic Weisbecker 	int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
112fcd14984SFrederic Weisbecker 	int	(*se_snprintf)(struct hist_entry *self, char *bf, size_t size,
113a4e3b956SArnaldo Carvalho de Melo 			       unsigned int width);
1148a6c5b26SArnaldo Carvalho de Melo 	u8	se_width_idx;
115dd68ada2SJohn Kacur 	bool	elide;
116dd68ada2SJohn Kacur };
117dd68ada2SJohn Kacur 
118dd68ada2SJohn Kacur extern struct sort_entry sort_thread;
119dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list;
120dd68ada2SJohn Kacur 
121c8829c7aSArnaldo Carvalho de Melo void setup_sorting(const char * const usagestr[], const struct option *opts);
122dd68ada2SJohn Kacur extern int sort_dimension__add(const char *);
123c351c281SArnaldo Carvalho de Melo void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
124c351c281SArnaldo Carvalho de Melo 			     const char *list_name, FILE *fp);
125dd68ada2SJohn Kacur 
126dd68ada2SJohn Kacur #endif	/* __PERF_SORT_H */
127