]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/perf/util/sort.h
perf evlist: Rename struct perf_evlist to struct evlist
[mirror_ubuntu-hirsute-kernel.git] / tools / perf / util / sort.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
dd68ada2
JK
2#ifndef __PERF_SORT_H
3#define __PERF_SORT_H
4#include "../builtin.h"
5
1eae20c1 6#include <regex.h>
dd68ada2
JK
7
8#include "color.h"
9#include <linux/list.h>
10#include "cache.h"
11#include <linux/rbtree.h>
9f4e8ff2
ACM
12#include "map_symbol.h"
13#include "symbol_conf.h"
dd68ada2
JK
14#include "string.h"
15#include "callchain.h"
dd68ada2
JK
16#include "values.h"
17
18#include "../perf.h"
19#include "debug.h"
20#include "header.h"
21
4b6ab94e 22#include <subcmd/parse-options.h>
dd68ada2 23#include "parse-events.h"
14135663 24#include "hist.h"
632a5cab 25#include "srcline.h"
e7ff8920
ACM
26
27struct thread;
dd68ada2
JK
28
29extern regex_t parent_regex;
edb7c60e 30extern const char *sort_order;
a7d945bc 31extern const char *field_order;
edb7c60e
ACM
32extern const char default_parent_pattern[];
33extern const char *parent_pattern;
fa1f4565 34extern const char *default_sort_order;
b21484f1
GP
35extern regex_t ignore_callees_regex;
36extern int have_ignore_callees;
55369fc1 37extern enum sort_mode sort__mode;
dd68ada2
JK
38extern struct sort_entry sort_comm;
39extern struct sort_entry sort_dso;
40extern struct sort_entry sort_sym;
41extern struct sort_entry sort_parent;
a68c2c58
SE
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;
f666ac0d 46extern struct sort_entry sort_srcline;
a4fb581b 47extern enum sort_type sort__first_dimension;
228f14f2 48extern const char default_mem_sort_order[];
dd68ada2 49
4968ac8f
AK
50struct res_sample {
51 u64 time;
52 int cpu;
53 int tid;
54};
55
b24c28f7
NK
56struct he_stat {
57 u64 period;
58 u64 period_sys;
59 u64 period_us;
60 u64 period_guest_sys;
61 u64 period_guest_us;
05484298 62 u64 weight;
b24c28f7
NK
63 u32 nr_events;
64};
65
d890a98c
HB
66struct namespace_id {
67 u64 dev;
68 u64 ino;
69};
70
96c47f19
JO
71struct hist_entry_diff {
72 bool computed;
a0b404f4
NK
73 union {
74 /* PERF_HPP__DELTA */
75 double period_ratio_delta;
96c47f19 76
a0b404f4
NK
77 /* PERF_HPP__RATIO */
78 double period_ratio;
81d5f958 79
a0b404f4
NK
80 /* HISTC_WEIGHTED_DIFF */
81 s64 wdiff;
99150a1f
JY
82
83 /* PERF_HPP_DIFF__CYCLES */
84 s64 cycles;
a0b404f4 85 };
96c47f19
JO
86};
87
f542e767
JO
88struct hist_entry_ops {
89 void *(*new)(size_t size);
90 void (*free)(void *ptr);
91};
92
0f0cbf7a
ACM
93/**
94 * struct hist_entry - histogram entry
95 *
96 * @row_offset - offset from the first callchain expanded to appear on screen
97 * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
98 */
dd68ada2 99struct hist_entry {
1980c2eb 100 struct rb_node rb_node_in;
dd68ada2 101 struct rb_node rb_node;
b821c732
ACM
102 union {
103 struct list_head node;
104 struct list_head head;
105 } pairs;
b24c28f7 106 struct he_stat stat;
f8be1c8c 107 struct he_stat *stat_acc;
59fd5306 108 struct map_symbol ms;
a5e29aca 109 struct thread *thread;
4dfced35 110 struct comm *comm;
d890a98c 111 struct namespace_id cgroup_id;
dd68ada2 112 u64 ip;
475eeab9 113 u64 transaction;
0c4c4deb 114 s32 socket;
f60f3593 115 s32 cpu;
7365be55 116 u8 cpumode;
aef810ec 117 u8 depth;
0f0cbf7a 118
e0af43d2
JO
119 /* We are added by hists__add_dummy_entry. */
120 bool dummy;
aef810ec 121 bool leaf;
e0af43d2 122
dd68ada2 123 char level;
a5e29aca 124 u8 filtered;
41477acf
ACM
125
126 u16 callchain_size;
29750821
NK
127 union {
128 /*
129 * Since perf diff only supports the stdio output, TUI
130 * fields are only accessed from perf report (or perf
03440c4e 131 * top). So make it a union to reduce memory usage.
29750821
NK
132 */
133 struct hist_entry_diff diff;
134 struct /* for TUI */ {
135 u16 row_offset;
136 u16 nr_rows;
d8a0f800 137 bool init_have_children;
3698dab1
NK
138 bool unfolded;
139 bool has_children;
79dded87 140 bool has_no_entry;
29750821
NK
141 };
142 };
409a8be6 143 char *srcline;
31191a85 144 char *srcfile;
83753190 145 struct symbol *parent;
b5387528 146 struct branch_info *branch_info;
3723908d 147 long time;
ae359f19 148 struct hists *hists;
98a3b32c 149 struct mem_info *mem_info;
fe96245c 150 struct block_info *block_info;
72392834
NK
151 void *raw_data;
152 u32 raw_size;
4968ac8f
AK
153 int num_res;
154 struct res_sample *res_samples;
60517d28 155 void *trace_output;
1b2dbbf4 156 struct perf_hpp_list *hpp_list;
aef810ec 157 struct hist_entry *parent_he;
f542e767 158 struct hist_entry_ops *ops;
aef810ec
NK
159 union {
160 /* this is for hierarchical entry structure */
161 struct {
2eb3d689
DB
162 struct rb_root_cached hroot_in;
163 struct rb_root_cached hroot_out;
aef810ec
NK
164 }; /* non-leaf entries */
165 struct rb_root sorted_chain; /* leaf entry has callchains */
166 };
98a3b32c 167 struct callchain_root callchain[0]; /* must be last member */
dd68ada2
JK
168};
169
0b5d6ece
ACM
170static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
171{
e5654455 172 return he->callchain_size != 0;
0b5d6ece
ACM
173}
174
b821c732
ACM
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
4d23322a
JO
187static inline void hist_entry__add_pair(struct hist_entry *pair,
188 struct hist_entry *he)
b821c732 189{
4d23322a 190 list_add_tail(&pair->pairs.node, &he->pairs.head);
b821c732
ACM
191}
192
14135663
NK
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
e95cf700
JO
207static inline u64 cl_address(u64 address)
208{
209 /* return the cacheline of the address */
9ac94e31 210 return (address & ~(cacheline_size() - 1));
e95cf700 211}
14135663 212
d3927110
JO
213static inline u64 cl_offset(u64 address)
214{
215 /* return the cacheline of the address */
9ac94e31 216 return (address & (cacheline_size() - 1));
d3927110
JO
217}
218
55369fc1
NK
219enum sort_mode {
220 SORT_MODE__NORMAL,
221 SORT_MODE__BRANCH,
222 SORT_MODE__MEMORY,
512ae1bd
NK
223 SORT_MODE__TOP,
224 SORT_MODE__DIFF,
d49dadea 225 SORT_MODE__TRACEPOINT,
55369fc1
NK
226};
227
a4fb581b 228enum sort_type {
fc5871ed 229 /* common sort keys */
a4fb581b
FW
230 SORT_PID,
231 SORT_COMM,
232 SORT_DSO,
233 SORT_SYM,
f60f3593
AS
234 SORT_PARENT,
235 SORT_CPU,
2e7ea3ab 236 SORT_SOCKET,
fc5871ed 237 SORT_SRCLINE,
31191a85 238 SORT_SRCFILE,
f9ea55d0
AK
239 SORT_LOCAL_WEIGHT,
240 SORT_GLOBAL_WEIGHT,
475eeab9 241 SORT_TRANSACTION,
a34bb6a0 242 SORT_TRACE,
7768f8da 243 SORT_SYM_SIZE,
b74d12d5 244 SORT_DSO_SIZE,
d890a98c 245 SORT_CGROUP_ID,
ec6ae74f 246 SORT_SYM_IPC_NULL,
3723908d 247 SORT_TIME,
fc5871ed
NK
248
249 /* branch stack specific sort keys */
250 __SORT_BRANCH_STACK,
251 SORT_DSO_FROM = __SORT_BRANCH_STACK,
b5387528
RAV
252 SORT_DSO_TO,
253 SORT_SYM_FROM,
254 SORT_SYM_TO,
255 SORT_MISPREDICT,
f5d05bce
AK
256 SORT_ABORT,
257 SORT_IN_TX,
0e332f03 258 SORT_CYCLES,
508be0df
AK
259 SORT_SRCLINE_FROM,
260 SORT_SRCLINE_TO,
ec6ae74f 261 SORT_SYM_IPC,
afab87b9
NK
262
263 /* memory mode specific sort keys */
264 __SORT_MEMORY_MODE,
f9ea55d0 265 SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
afab87b9
NK
266 SORT_MEM_DADDR_DSO,
267 SORT_MEM_LOCKED,
268 SORT_MEM_TLB,
269 SORT_MEM_LVL,
270 SORT_MEM_SNOOP,
9b32ba71 271 SORT_MEM_DCACHELINE,
28e6db20 272 SORT_MEM_IADDR_SYMBOL,
8780fb25 273 SORT_MEM_PHYS_DADDR,
a4fb581b
FW
274};
275
dd68ada2
JK
276/*
277 * configurable sorting bits
278 */
279
280struct sort_entry {
fcd14984 281 const char *se_header;
dd68ada2 282
fcd14984
FW
283 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
284 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
202e7a6d 285 int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
316c7136 286 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
fcd14984 287 unsigned int width);
54430101 288 int (*se_filter)(struct hist_entry *he, int type, const void *arg);
8a6c5b26 289 u8 se_width_idx;
dd68ada2
JK
290};
291
99150a1f
JY
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
dd68ada2
JK
301extern struct sort_entry sort_thread;
302extern struct list_head hist_entry__sort_list;
303
63503dba 304struct evlist;
096177a8 305struct tep_handle;
63503dba 306int setup_sorting(struct evlist *evlist);
a7d945bc 307int setup_output_field(void);
1c89fe9b 308void reset_output_field(void);
08e71542 309void sort__setup_elide(FILE *fp);
f2998422 310void perf_hpp__set_elide(int idx, bool elide);
dd68ada2 311
702fb9b4
AK
312const char *sort_help(const char *prefix);
313
b21484f1
GP
314int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
315
2f3f9bcf 316bool is_strict_order(const char *order);
beeaaeb3
JO
317
318int hpp_dimension__add_output(unsigned col);
bcf98740 319void reset_dimensions(void);
a76490e4 320int sort_dimension__add(struct perf_hpp_list *list, const char *tok,
63503dba 321 struct evlist *evlist,
a76490e4
JO
322 int level);
323int output_field_add(struct perf_hpp_list *list, char *tok);
5fe7b9b4
JO
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);
6a53da05 330char *hist_entry__srcline(struct hist_entry *he);
dd68ada2 331#endif /* __PERF_SORT_H */