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 s64 cycles;
85 };
86};
87
88struct hist_entry_ops {
89 void *(*new)(size_t size);
90 void (*free)(void *ptr);
91};
92
93
94
95
96
97
98
99struct hist_entry {
100 struct rb_node rb_node_in;
101 struct rb_node rb_node;
102 union {
103 struct list_head node;
104 struct list_head head;
105 } pairs;
106 struct he_stat stat;
107 struct he_stat *stat_acc;
108 struct map_symbol ms;
109 struct thread *thread;
110 struct comm *comm;
111 struct namespace_id cgroup_id;
112 u64 ip;
113 u64 transaction;
114 s32 socket;
115 s32 cpu;
116 u8 cpumode;
117 u8 depth;
118
119
120 bool dummy;
121 bool leaf;
122
123 char level;
124 u8 filtered;
125
126 u16 callchain_size;
127 union {
128
129
130
131
132
133 struct hist_entry_diff diff;
134 struct {
135 u16 row_offset;
136 u16 nr_rows;
137 bool init_have_children;
138 bool unfolded;
139 bool has_children;
140 bool has_no_entry;
141 };
142 };
143 char *srcline;
144 char *srcfile;
145 struct symbol *parent;
146 struct branch_info *branch_info;
147 long time;
148 struct hists *hists;
149 struct mem_info *mem_info;
150 struct block_info *block_info;
151 void *raw_data;
152 u32 raw_size;
153 int num_res;
154 struct res_sample *res_samples;
155 void *trace_output;
156 struct perf_hpp_list *hpp_list;
157 struct hist_entry *parent_he;
158 struct hist_entry_ops *ops;
159 union {
160
161 struct {
162 struct rb_root_cached hroot_in;
163 struct rb_root_cached hroot_out;
164 };
165 struct rb_root sorted_chain;
166 };
167 struct callchain_root callchain[0];
168};
169
170static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
171{
172 return he->callchain_size != 0;
173}
174
175static inline bool hist_entry__has_pairs(struct hist_entry *he)
176{
177 return !list_empty(&he->pairs.node);
178}
179
180static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
181{
182 if (hist_entry__has_pairs(he))
183 return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
184 return NULL;
185}
186
187static inline void hist_entry__add_pair(struct hist_entry *pair,
188 struct hist_entry *he)
189{
190 list_add_tail(&pair->pairs.node, &he->pairs.head);
191}
192
193static inline float hist_entry__get_percent_limit(struct hist_entry *he)
194{
195 u64 period = he->stat.period;
196 u64 total_period = hists__total_period(he->hists);
197
198 if (unlikely(total_period == 0))
199 return 0;
200
201 if (symbol_conf.cumulate_callchain)
202 period = he->stat_acc->period;
203
204 return period * 100.0 / total_period;
205}
206
207static inline u64 cl_address(u64 address)
208{
209
210 return (address & ~(cacheline_size() - 1));
211}
212
213static inline u64 cl_offset(u64 address)
214{
215
216 return (address & (cacheline_size() - 1));
217}
218
219enum sort_mode {
220 SORT_MODE__NORMAL,
221 SORT_MODE__BRANCH,
222 SORT_MODE__MEMORY,
223 SORT_MODE__TOP,
224 SORT_MODE__DIFF,
225 SORT_MODE__TRACEPOINT,
226};
227
228enum sort_type {
229
230 SORT_PID,
231 SORT_COMM,
232 SORT_DSO,
233 SORT_SYM,
234 SORT_PARENT,
235 SORT_CPU,
236 SORT_SOCKET,
237 SORT_SRCLINE,
238 SORT_SRCFILE,
239 SORT_LOCAL_WEIGHT,
240 SORT_GLOBAL_WEIGHT,
241 SORT_TRANSACTION,
242 SORT_TRACE,
243 SORT_SYM_SIZE,
244 SORT_DSO_SIZE,
245 SORT_CGROUP_ID,
246 SORT_SYM_IPC_NULL,
247 SORT_TIME,
248
249
250 __SORT_BRANCH_STACK,
251 SORT_DSO_FROM = __SORT_BRANCH_STACK,
252 SORT_DSO_TO,
253 SORT_SYM_FROM,
254 SORT_SYM_TO,
255 SORT_MISPREDICT,
256 SORT_ABORT,
257 SORT_IN_TX,
258 SORT_CYCLES,
259 SORT_SRCLINE_FROM,
260 SORT_SRCLINE_TO,
261 SORT_SYM_IPC,
262
263
264 __SORT_MEMORY_MODE,
265 SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
266 SORT_MEM_DADDR_DSO,
267 SORT_MEM_LOCKED,
268 SORT_MEM_TLB,
269 SORT_MEM_LVL,
270 SORT_MEM_SNOOP,
271 SORT_MEM_DCACHELINE,
272 SORT_MEM_IADDR_SYMBOL,
273 SORT_MEM_PHYS_DADDR,
274};
275
276
277
278
279
280struct sort_entry {
281 const char *se_header;
282
283 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
284 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
285 int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
286 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
287 unsigned int width);
288 int (*se_filter)(struct hist_entry *he, int type, const void *arg);
289 u8 se_width_idx;
290};
291
292struct block_hist {
293 struct hists block_hists;
294 struct perf_hpp_list block_list;
295 struct perf_hpp_fmt block_fmt;
296 int block_idx;
297 bool valid;
298 struct hist_entry he;
299};
300
301extern struct sort_entry sort_thread;
302extern struct list_head hist_entry__sort_list;
303
304struct perf_evlist;
305struct tep_handle;
306int setup_sorting(struct perf_evlist *evlist);
307int setup_output_field(void);
308void reset_output_field(void);
309void sort__setup_elide(FILE *fp);
310void perf_hpp__set_elide(int idx, bool elide);
311
312const char *sort_help(const char *prefix);
313
314int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
315
316bool is_strict_order(const char *order);
317
318int hpp_dimension__add_output(unsigned col);
319void reset_dimensions(void);
320int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
321 struct perf_evlist *evlist,
322 int level);
323int output_field_add(struct perf_hpp_list *list, char *tok);
324int64_t
325sort__iaddr_cmp(struct hist_entry *left, struct hist_entry *right);
326int64_t
327sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right);
328int64_t
329sort__dcacheline_cmp(struct hist_entry *left, struct hist_entry *right);
330char *hist_entry__srcline(struct hist_entry *he);
331#endif
332