1
2#ifndef __PERF_SORT_H
3#define __PERF_SORT_H
4#include "../builtin.h"
5
6#include <regex.h>
7
8#include "color.h"
9#include <linux/list.h>
10#include "cache.h"
11#include <linux/rbtree.h>
12#include "map_symbol.h"
13#include "symbol_conf.h"
14#include "string.h"
15#include "callchain.h"
16#include "values.h"
17
18#include "../perf.h"
19#include "debug.h"
20#include "header.h"
21
22#include <subcmd/parse-options.h>
23#include "parse-events.h"
24#include "hist.h"
25#include "srcline.h"
26
27struct thread;
28
29extern regex_t parent_regex;
30extern const char *sort_order;
31extern const char *field_order;
32extern const char default_parent_pattern[];
33extern const char *parent_pattern;
34extern const char *default_sort_order;
35extern regex_t ignore_callees_regex;
36extern int have_ignore_callees;
37extern enum sort_mode sort__mode;
38extern struct sort_entry sort_comm;
39extern struct sort_entry sort_dso;
40extern struct sort_entry sort_sym;
41extern struct sort_entry sort_parent;
42extern struct sort_entry sort_dso_from;
43extern struct sort_entry sort_dso_to;
44extern struct sort_entry sort_sym_from;
45extern struct sort_entry sort_sym_to;
46extern struct sort_entry sort_srcline;
47extern enum sort_type sort__first_dimension;
48extern const char default_mem_sort_order[];
49
50struct res_sample {
51 u64 time;
52 int cpu;
53 int tid;
54};
55
56struct he_stat {
57 u64 period;
58 u64 period_sys;
59 u64 period_us;
60 u64 period_guest_sys;
61 u64 period_guest_us;
62 u64 weight;
63 u32 nr_events;
64};
65
66struct namespace_id {
67 u64 dev;
68 u64 ino;
69};
70
71struct hist_entry_diff {
72 bool computed;
73 union {
74
75 double period_ratio_delta;
76
77
78 double period_ratio;
79
80
81 s64 wdiff;
82 };
83};
84
85struct hist_entry_ops {
86 void *(*new)(size_t size);
87 void (*free)(void *ptr);
88};
89
90
91
92
93
94
95
96struct hist_entry {
97 struct rb_node rb_node_in;
98 struct rb_node rb_node;
99 union {
100 struct list_head node;
101 struct list_head head;
102 } pairs;
103 struct he_stat stat;
104 struct he_stat *stat_acc;
105 struct map_symbol ms;
106 struct thread *thread;
107 struct comm *comm;
108 struct namespace_id cgroup_id;
109 u64 ip;
110 u64 transaction;
111 s32 socket;
112 s32 cpu;
113 u8 cpumode;
114 u8 depth;
115
116
117 bool dummy;
118 bool leaf;
119
120 char level;
121 u8 filtered;
122
123 u16 callchain_size;
124 union {
125
126
127
128
129
130 struct hist_entry_diff diff;
131 struct {
132 u16 row_offset;
133 u16 nr_rows;
134 bool init_have_children;
135 bool unfolded;
136 bool has_children;
137 bool has_no_entry;
138 };
139 };
140 char *srcline;
141 char *srcfile;
142 struct symbol *parent;
143 struct branch_info *branch_info;
144 long time;
145 struct hists *hists;
146 struct mem_info *mem_info;
147 void *raw_data;
148 u32 raw_size;
149 int num_res;
150 struct res_sample *res_samples;
151 void *trace_output;
152 struct perf_hpp_list *hpp_list;
153 struct hist_entry *parent_he;
154 struct hist_entry_ops *ops;
155 union {
156
157 struct {
158 struct rb_root_cached hroot_in;
159 struct rb_root_cached hroot_out;
160 };
161 struct rb_root sorted_chain;
162 };
163 struct callchain_root callchain[0];
164};
165
166static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
167{
168 return he->callchain_size != 0;
169}
170
171static inline bool hist_entry__has_pairs(struct hist_entry *he)
172{
173 return !list_empty(&he->pairs.node);
174}
175
176static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
177{
178 if (hist_entry__has_pairs(he))
179 return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
180 return NULL;
181}
182
183static inline void hist_entry__add_pair(struct hist_entry *pair,
184 struct hist_entry *he)
185{
186 list_add_tail(&pair->pairs.node, &he->pairs.head);
187}
188
189static inline float hist_entry__get_percent_limit(struct hist_entry *he)
190{
191 u64 period = he->stat.period;
192 u64 total_period = hists__total_period(he->hists);
193
194 if (unlikely(total_period == 0))
195 return 0;
196
197 if (symbol_conf.cumulate_callchain)
198 period = he->stat_acc->period;
199
200 return period * 100.0 / total_period;
201}
202
203static inline u64 cl_address(u64 address)
204{
205
206 return (address & ~(cacheline_size() - 1));
207}
208
209static inline u64 cl_offset(u64 address)
210{
211
212 return (address & (cacheline_size() - 1));
213}
214
215enum sort_mode {
216 SORT_MODE__NORMAL,
217 SORT_MODE__BRANCH,
218 SORT_MODE__MEMORY,
219 SORT_MODE__TOP,
220 SORT_MODE__DIFF,
221 SORT_MODE__TRACEPOINT,
222};
223
224enum sort_type {
225
226 SORT_PID,
227 SORT_COMM,
228 SORT_DSO,
229 SORT_SYM,
230 SORT_PARENT,
231 SORT_CPU,
232 SORT_SOCKET,
233 SORT_SRCLINE,
234 SORT_SRCFILE,
235 SORT_LOCAL_WEIGHT,
236 SORT_GLOBAL_WEIGHT,
237 SORT_TRANSACTION,
238 SORT_TRACE,
239 SORT_SYM_SIZE,
240 SORT_DSO_SIZE,
241 SORT_CGROUP_ID,
242 SORT_SYM_IPC_NULL,
243 SORT_TIME,
244
245
246 __SORT_BRANCH_STACK,
247 SORT_DSO_FROM = __SORT_BRANCH_STACK,
248 SORT_DSO_TO,
249 SORT_SYM_FROM,
250 SORT_SYM_TO,
251 SORT_MISPREDICT,
252 SORT_ABORT,
253 SORT_IN_TX,
254 SORT_CYCLES,
255 SORT_SRCLINE_FROM,
256 SORT_SRCLINE_TO,
257 SORT_SYM_IPC,
258
259
260 __SORT_MEMORY_MODE,
261 SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
262 SORT_MEM_DADDR_DSO,
263 SORT_MEM_LOCKED,
264 SORT_MEM_TLB,
265 SORT_MEM_LVL,
266 SORT_MEM_SNOOP,
267 SORT_MEM_DCACHELINE,
268 SORT_MEM_IADDR_SYMBOL,
269 SORT_MEM_PHYS_DADDR,
270};
271
272
273
274
275
276struct sort_entry {
277 const char *se_header;
278
279 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
280 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
281 int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
282 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
283 unsigned int width);
284 int (*se_filter)(struct hist_entry *he, int type, const void *arg);
285 u8 se_width_idx;
286};
287
288extern struct sort_entry sort_thread;
289extern struct list_head hist_entry__sort_list;
290
291struct perf_evlist;
292struct tep_handle;
293int setup_sorting(struct perf_evlist *evlist);
294int setup_output_field(void);
295void reset_output_field(void);
296void sort__setup_elide(FILE *fp);
297void perf_hpp__set_elide(int idx, bool elide);
298
299const char *sort_help(const char *prefix);
300
301int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
302
303bool is_strict_order(const char *order);
304
305int hpp_dimension__add_output(unsigned col);
306void reset_dimensions(void);
307int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
308 struct perf_evlist *evlist,
309 int level);
310int output_field_add(struct perf_hpp_list *list, char *tok);
311int64_t
312sort__iaddr_cmp(struct hist_entry *left, struct hist_entry *right);
313int64_t
314sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right);
315int64_t
316sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right);
317char *hist_entry__srcline(struct hist_entry *he);
318#endif
319