xref: /openbmc/linux/tools/perf/util/sort.h (revision c82ee828)
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;
28dd68ada2SJohn Kacur extern char *sort_order;
29dd68ada2SJohn Kacur extern char default_parent_pattern[];
30dd68ada2SJohn Kacur extern char *parent_pattern;
31dd68ada2SJohn Kacur extern 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;
39dd68ada2SJohn Kacur extern unsigned int dsos__col_width;
40dd68ada2SJohn Kacur extern unsigned int comms__col_width;
41dd68ada2SJohn Kacur extern unsigned int threads__col_width;
42a4fb581bSFrederic Weisbecker extern enum sort_type sort__first_dimension;
43dd68ada2SJohn Kacur 
44dd68ada2SJohn Kacur struct hist_entry {
45dd68ada2SJohn Kacur 	struct rb_node		rb_node;
46c82ee828SArnaldo Carvalho de Melo 	u64			period;
47c82ee828SArnaldo Carvalho de Melo 	u64			period_sys;
48c82ee828SArnaldo Carvalho de Melo 	u64			period_us;
49c82ee828SArnaldo Carvalho de Melo 	u64			period_guest_sys;
50c82ee828SArnaldo Carvalho de Melo 	u64			period_guest_us;
5159fd5306SArnaldo Carvalho de Melo 	struct map_symbol	ms;
52a5e29acaSArnaldo Carvalho de Melo 	struct thread		*thread;
53dd68ada2SJohn Kacur 	u64			ip;
54c82ee828SArnaldo Carvalho de Melo 	u32			nr_events;
55dd68ada2SJohn Kacur 	char			level;
56a5e29acaSArnaldo Carvalho de Melo 	u8			filtered;
57439d473bSArnaldo Carvalho de Melo 	struct symbol		*parent;
5886a9eee0SArnaldo Carvalho de Melo 	union {
5986a9eee0SArnaldo Carvalho de Melo 		unsigned long	  position;
6086a9eee0SArnaldo Carvalho de Melo 		struct hist_entry *pair;
61dd68ada2SJohn Kacur 		struct rb_root	  sorted_chain;
62dd68ada2SJohn Kacur 	};
63b9fb9304SArnaldo Carvalho de Melo 	struct callchain_node	callchain[0];
6486a9eee0SArnaldo Carvalho de Melo };
65dd68ada2SJohn Kacur 
66a4fb581bSFrederic Weisbecker enum sort_type {
67a4fb581bSFrederic Weisbecker 	SORT_PID,
68a4fb581bSFrederic Weisbecker 	SORT_COMM,
69a4fb581bSFrederic Weisbecker 	SORT_DSO,
70a4fb581bSFrederic Weisbecker 	SORT_SYM,
71a4fb581bSFrederic Weisbecker 	SORT_PARENT
72a4fb581bSFrederic Weisbecker };
73a4fb581bSFrederic Weisbecker 
74dd68ada2SJohn Kacur /*
75dd68ada2SJohn Kacur  * configurable sorting bits
76dd68ada2SJohn Kacur  */
77dd68ada2SJohn Kacur 
78dd68ada2SJohn Kacur struct sort_entry {
79dd68ada2SJohn Kacur 	struct list_head list;
80dd68ada2SJohn Kacur 
81fcd14984SFrederic Weisbecker 	const char *se_header;
82dd68ada2SJohn Kacur 
83fcd14984SFrederic Weisbecker 	int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
84fcd14984SFrederic Weisbecker 	int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
85fcd14984SFrederic Weisbecker 	int	(*se_snprintf)(struct hist_entry *self, char *bf, size_t size,
86a4e3b956SArnaldo Carvalho de Melo 			       unsigned int width);
87fcd14984SFrederic Weisbecker 	unsigned int *se_width;
88dd68ada2SJohn Kacur 	bool	elide;
89dd68ada2SJohn Kacur };
90dd68ada2SJohn Kacur 
91dd68ada2SJohn Kacur extern struct sort_entry sort_thread;
92dd68ada2SJohn Kacur extern struct list_head hist_entry__sort_list;
93dd68ada2SJohn Kacur 
94c8829c7aSArnaldo Carvalho de Melo void setup_sorting(const char * const usagestr[], const struct option *opts);
95c8829c7aSArnaldo Carvalho de Melo 
96dd68ada2SJohn Kacur extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int);
97dd68ada2SJohn Kacur extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int);
98dd68ada2SJohn Kacur extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int);
99dd68ada2SJohn Kacur extern size_t sort__sym_print(FILE *, struct hist_entry *, unsigned int __used);
100dd68ada2SJohn Kacur extern int64_t cmp_null(void *, void *);
101dd68ada2SJohn Kacur extern int64_t sort__thread_cmp(struct hist_entry *, struct hist_entry *);
102dd68ada2SJohn Kacur extern int64_t sort__comm_cmp(struct hist_entry *, struct hist_entry *);
103dd68ada2SJohn Kacur extern int64_t sort__comm_collapse(struct hist_entry *, struct hist_entry *);
104dd68ada2SJohn Kacur extern int64_t sort__dso_cmp(struct hist_entry *, struct hist_entry *);
105dd68ada2SJohn Kacur extern int64_t sort__sym_cmp(struct hist_entry *, struct hist_entry *);
106dd68ada2SJohn Kacur extern int64_t sort__parent_cmp(struct hist_entry *, struct hist_entry *);
107dd68ada2SJohn Kacur extern size_t sort__parent_print(FILE *, struct hist_entry *, unsigned int);
108dd68ada2SJohn Kacur extern int sort_dimension__add(const char *);
109c351c281SArnaldo Carvalho de Melo void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
110c351c281SArnaldo Carvalho de Melo 			     const char *list_name, FILE *fp);
111dd68ada2SJohn Kacur 
112dd68ada2SJohn Kacur #endif	/* __PERF_SORT_H */
113