xref: /openbmc/linux/tools/perf/util/sort.h (revision 1980c2eb)
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;
34dd68ada2SJohn Kacur extern char *field_sep;
35dd68ada2SJohn Kacur extern struct sort_entry sort_comm;
36dd68ada2SJohn Kacur extern struct sort_entry sort_dso;
37dd68ada2SJohn Kacur extern struct sort_entry sort_sym;
38dd68ada2SJohn Kacur extern struct sort_entry sort_parent;
39a4fb581bSFrederic Weisbecker extern enum sort_type sort__first_dimension;
40dd68ada2SJohn Kacur 
410f0cbf7aSArnaldo Carvalho de Melo /**
420f0cbf7aSArnaldo Carvalho de Melo  * struct hist_entry - histogram entry
430f0cbf7aSArnaldo Carvalho de Melo  *
440f0cbf7aSArnaldo Carvalho de Melo  * @row_offset - offset from the first callchain expanded to appear on screen
450f0cbf7aSArnaldo Carvalho de Melo  * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
460f0cbf7aSArnaldo Carvalho de Melo  */
47dd68ada2SJohn Kacur struct hist_entry {
481980c2ebSArnaldo Carvalho de Melo 	struct rb_node		rb_node_in;
49dd68ada2SJohn Kacur 	struct rb_node		rb_node;
50c82ee828SArnaldo Carvalho de Melo 	u64			period;
51c82ee828SArnaldo Carvalho de Melo 	u64			period_sys;
52c82ee828SArnaldo Carvalho de Melo 	u64			period_us;
53c82ee828SArnaldo Carvalho de Melo 	u64			period_guest_sys;
54c82ee828SArnaldo Carvalho de Melo 	u64			period_guest_us;
5559fd5306SArnaldo Carvalho de Melo 	struct map_symbol	ms;
56a5e29acaSArnaldo Carvalho de Melo 	struct thread		*thread;
57dd68ada2SJohn Kacur 	u64			ip;
58f60f3593SArun Sharma 	s32			cpu;
59c82ee828SArnaldo Carvalho de Melo 	u32			nr_events;
600f0cbf7aSArnaldo Carvalho de Melo 
610f0cbf7aSArnaldo Carvalho de Melo 	/* XXX These two should move to some tree widget lib */
620f0cbf7aSArnaldo Carvalho de Melo 	u16			row_offset;
630f0cbf7aSArnaldo Carvalho de Melo 	u16			nr_rows;
640f0cbf7aSArnaldo Carvalho de Melo 
650f0cbf7aSArnaldo Carvalho de Melo 	bool			init_have_children;
66dd68ada2SJohn Kacur 	char			level;
67a5e29acaSArnaldo Carvalho de Melo 	u8			filtered;
68439d473bSArnaldo Carvalho de Melo 	struct symbol		*parent;
6986a9eee0SArnaldo Carvalho de Melo 	union {
7086a9eee0SArnaldo Carvalho de Melo 		unsigned long	  position;
7186a9eee0SArnaldo Carvalho de Melo 		struct hist_entry *pair;
72dd68ada2SJohn Kacur 		struct rb_root	  sorted_chain;
73dd68ada2SJohn Kacur 	};
74d2009c51SFrederic Weisbecker 	struct callchain_root	callchain[0];
7586a9eee0SArnaldo Carvalho de Melo };
76dd68ada2SJohn Kacur 
77a4fb581bSFrederic Weisbecker enum sort_type {
78a4fb581bSFrederic Weisbecker 	SORT_PID,
79a4fb581bSFrederic Weisbecker 	SORT_COMM,
80a4fb581bSFrederic Weisbecker 	SORT_DSO,
81a4fb581bSFrederic Weisbecker 	SORT_SYM,
82f60f3593SArun Sharma 	SORT_PARENT,
83f60f3593SArun Sharma 	SORT_CPU,
84a4fb581bSFrederic Weisbecker };
85a4fb581bSFrederic Weisbecker 
86dd68ada2SJohn Kacur /*
87dd68ada2SJohn Kacur  * configurable sorting bits
88dd68ada2SJohn Kacur  */
89dd68ada2SJohn Kacur 
90dd68ada2SJohn Kacur struct sort_entry {
91dd68ada2SJohn Kacur 	struct list_head list;
92dd68ada2SJohn Kacur 
93fcd14984SFrederic Weisbecker 	const char *se_header;
94dd68ada2SJohn Kacur 
95fcd14984SFrederic Weisbecker 	int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
96fcd14984SFrederic Weisbecker 	int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
97fcd14984SFrederic Weisbecker 	int	(*se_snprintf)(struct hist_entry *self, char *bf, size_t size,
98a4e3b956SArnaldo Carvalho de Melo 			       unsigned int width);
998a6c5b26SArnaldo Carvalho de Melo 	u8	se_width_idx;
100dd68ada2SJohn Kacur 	bool	elide;
101dd68ada2SJohn Kacur };
102dd68ada2SJohn Kacur 
103dd68ada2SJohn Kacur extern struct sort_entry sort_thread;
104dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list;
105dd68ada2SJohn Kacur 
106c8829c7aSArnaldo Carvalho de Melo void setup_sorting(const char * const usagestr[], const struct option *opts);
107dd68ada2SJohn Kacur extern int sort_dimension__add(const char *);
108c351c281SArnaldo Carvalho de Melo void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
109c351c281SArnaldo Carvalho de Melo 			     const char *list_name, FILE *fp);
110dd68ada2SJohn Kacur 
111dd68ada2SJohn Kacur #endif	/* __PERF_SORT_H */
112